DO NOT CHANGE WHEELS
Edit: Saving UserId - you don't need to. You can get it from MemberhipProvider anytime the user logs in, of course:
MembershipUser user = Membership.GetUser(); Guid UserID = user.ProviderUserKey;
It seems to me that you need to implement ASP.NET Memberhip Provider. Read this resource: http://odetocode.com/articles/427.aspx
Also a good series by Scott Guthrie: http://weblogs.asp.net/scottgu/archive/2006/02/24/ASP.NET-2.0-Membership_2C00_-Roles_2C00_-Forms-Authentication_2C00_-and-Security-Resources-. aspx
In general, use this approach: use authentication to authenticate the user. This is the protected side of authentication. That is, a user definition is one who, as they say, usually with a username and password.
The second part of security is authorization, which happens when you know who the user is. This is basically a definition of what resources an authenticated user has access to. A mature system will include the following objects:
User: may contain extended profile information captured on registration Resource: a page or other resource that can be restricted. Group: a group of users who can access resources due to their group membership (groups are granted resource access) Role: a type of user such as Administrator/Developer/Salesperson.
Thus, in order to provide the user with access to routeid 854 (resource), you can provide the resource directly to the user or if there are several users who should have access to this resource, and these users form a natural group, then create this group, provide the resource to the group and Add user to group.
Then you can access User.Resources with the resource identifier or protect the entire page with
if(!User.IsInRole("RoleName")) {
There are many good things available using a provider model.
Edit: you need to know something if you decide to store your user profile information. The default implementation of ProfileProvider is not particularly good. Scott Guthrie wrote a good article about a table-based provider, which is better: http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx
Daniel Dyson
source share