Every ASP.NET developer should already know about the Membership Provider that ships with ASP.NET 2.0. Configuring it is as easy as opening Visual Studio > select the Web project file > navigate to the Project menu item > and select “ASP.NET Configuration”. Follow the wizard and you are up and running now.
But the problem with this approach is that it will build it’s OWN database in the App_Data folder and create the required tables there. Wouldn’t most of us have their own databases to work with? ok then, if you want the defualt ASP.NET Membership Provide (AspNetSqlMembershipProvider) to work on YOUR database do the following:
- Navigate to the folder: “C:\Windows\Microsoft.NET\Framework\v2.0.50727” and run the “aspnet_regsql.exe” file, follow the wizard (it’s pretty easy, see the images below)
This step will create the Membership and Profile Provider tables necessary; if you are lucky you will see many dbo.aspnet_something tables.
- Now we need to tell the website which Provider it should use for this functionality, and to which database it should connect to; the default configuration information that drives the default behavior of the default Provider resides in the Machine.config (C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG), which explains why you can’t find the configuration information on YOUR web.config even after you finish using the ASP.NET Configuration mini-website.
The best thing to do is to copy that configuration information from the machine.config to your website web.config in order to override its behavior to our desired one, for more information about configuration files and configuration hierarchy read this.
<membership defaultProvider=“AspNetSqlMembershipProvider“ >
<add name=“AspNetSqlMembershipProvider“ type=“System.Web.Security.SqlMembershipProvider, System.Web, Version=188.8.131.52, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a“ connectionStringName=”BunianConnectionString” enablePasswordRetrieval=“false“ enablePasswordReset=“true“ requiresQuestionAndAnswer=“true“ applicationName=“/“ requiresUniqueEmail=“false“ passwordFormat=“Hashed“ maxInvalidPasswordAttempts=“5“ minRequiredPasswordLength=“7“ minRequiredNonalphanumericCharacters=“1“ passwordAttemptWindow=“10“ passwordStrengthRegularExpression=“”/>
Note that highlighted changes:
- clear any previous configuration of the AspNetSqlMebershipProvider (machine.config) which if not moved will give you an error of already being configured
- changing the connection string to mach a connectionstring name that you use to connect to your database in general
This way you will have the default Membership Provider running on your database for your website; if you use the mini-site for the ASP.NET Configuration now and create new users, you will find them created in your database.
Note that some resources say that you can change the database from the ASP.NET Configuration but I couldn’t find it there.
Disclaimer: use the above on your own responsibility