Yeah, I’ve Done That: ASP.NET Profiles
ASP.NET profiles are used to store user information in a database.
HttpModule in the pipeline: the ProfileModule which creates the profile object during the AcquireRequestState event of the request processing life-cycle.
When a web application is started, ASP.NET dynamically generates source code to create a class called ProfileCommon. The properties defined on this class are found in the section of the web.config file. These properties can be defined either in a element within the element or they can be defined by creating a class and referencing that class via the inherits attribute of the element.
Describing the properties within the element is a bad idea. This localizes the definition of ProfileCommon to your web app. and does not allow you to use this definition in other projects like web services. Sure, if your website is small and you don’t think in the future that web services or other projects will need to consume this information then define these properties in the element; but thinking like that will surely come back to bite you.
Note: If you had created your website as a Visual Studio Web Site project and then converted it to a Visual Studio ASP.NET Web Application project (as all good website projects should be) then the build mechanism for a web app. will not generate the ProfileCommon class for you. This means that all those custom properties you defined when the app. was a Web Site project are no longer available (generated) since the project is now a regular ASP.NET web app. project. For an ASP.NET web app. project you are forced to create a separate class to hold these properties. As luck would have it, this is a Good Thing.
Far better is to create a class—I like to call it UserProfile—that has the properties defined within it. Then point the ASP.NET profile code to this class via the inherits attribute on the element:
This causes ASP.NET, during app. startup, to create a class called ProfileCommon which inherits from UserProfile. Your UserProfile class itself is derived from ProfileBase. During the AcquireRequestState processing, ASP.NET creates an instance of the ProfileCommon class and makes it available to your code via the Profile property of the page’s HttpContext object.
Here’s an example UserProfile class for you VBers:
Using this class you can now get at the name of the user’s preferred language by referencing the Profile.PreferredLanguageName property in a Web form’s code-behind file.
Profiles In ASP.NET 2.0 by Scott Allen.
Examining ASP.NET's Membership, Roles, and Profile by Scott Mitchell.
System.Web.Profile @ MSDN.
Please share your comments about this article on my blog!