ASP.NET Profile Providers

Switch View :
ScriptFree
.NET Framework 4 - ASP.NET
ASP.NET Profile Providers

The ASP.NET profile feature uses the same provider-based structure used by ASP.NET membership, ASP.NET role management, and other ASP.NET features. The ASP.NET profile feature works as a tiered system in which the functionality of the profile feature—providing typed property values and managing user identities—is separated from the underlying data storage. The profile feature relies on profile providers (data providers) to perform the back-end tasks required to store and retrieve profile property values.

Default Profile Provider

ASP.NET includes a profile provider that stores data using Microsoft SQL Server. The default ASP.NET machine configuration contains a default SqlProfileProvider instance named AspNetSqlProfileProvider that connects to SQL Server on the local machine. By default, the ASP.NET profile feature uses this instance of the provider. Alternatively, you can specify a different default provider in your application's Web.config file.

To use a SqlProfileProvider, you must first create the SQL Server database used by the SqlProfileProvider. You can create the database by running the Aspnet_regsql.exe command, which is found in the following path:

systemroot\Microsoft .NET\SDK\version

When you run the tool, you specify the -Ap option. The following command shows the syntax that you use to create the database required to store ASP.NET profiles using the SqlProfileProvider:

aspnet_regsql.exe -Ap

The example above does not specify a name for the database that is created, so the default name will be used. The default database name is Aspnetdb.

If the profile provider is configured with a connection string that uses integrated security, the process account of the ASP.NET application must have rights to connect to the SQL Server database.

Note Note

If you are using a SQL Server 2005 Express Edition database that is installed using the default configuration and the database is on the same computer as the Web server, the profile database will be created automatically by ASP.NET.

Custom Profile Providers

In some cases, you might want to create and use a custom profile provider. This is often true if you already have a database that stores user information, such as an employee database, if you need to use a database other than Microsoft SQL Server, or if you need to use a different data store, such as XML files. For more information, see Implementing a Profile Provider.

The properties stored in a user profile can all be served by different profile providers. You can therefore manage data from multiple data sources to store information for a single user profile.

See Also

Concepts

Community Content

alex440
great comment! thank you andrew, you made my day.
-

Andrew Jens
Note the difference between Website and Web Application projects
Please note the difference between a Website project and a Web Application project (in regards to Profiles). $0$0 $0With a Website project you automatically get a class called ProfileCommon (in the App_Code folder) that wraps up the get/set code for any properties you add to the Profile. Everything is done for you, and you can stop thinking.$0 $0$0 $0 $0On the other hand, with a Web Application project, you get: nothing. There is an add-on to Visual Studio that allows you to right-click the Web.Config file and select "Generate WebProfile". If you do that, a WebProfile.cs class will be generated that gives you the equivalent functionality of the ProfileCommon class in a Website project. Unfortunately, the generation of the WebProfile.cs class in a Web Application project is not automatic, and you have to regenerate the class every time you make a change to the Profile properties in the Web.Config file.$0 $0$0 $0 $0Many programmers recommend that you create your own ProfileCommon (or similar name) class if using a Web Application project. Your class will have to inherit from the ProfileBase class (and there are plenty of samples on the web for implementing your own ProfileCommon class). Of course that isn't awfully automatic either, and you will have to update it whenever you make changes to the properties in the profile; but at least it is under your own control (and you don't have to right-click anything).$0 $0 $0$0 $0 $0Before tackling custom profiles, make sure you understand if you are working on a Website or a Web Application project.$0