Scott on Writing

Musings on technical writing...

Referencing the ASPNETDB Database

One of ASP.NET 2.0's coolest new features is the Membership system, which provides a standardized means for implementing user accounts on a system along with an API for interacting with the user accounts in the system. The Membership system using the provider model, meaning that you can customize the inner working of Membership if needed in order to use your custom user account data store. You can learn more about Membership and its cousin systems, Roles and Profile, in the multi-part article series Examining ASP.NET 2.0's Membership, Roles, and Profile (subscribe).

As discussed in the article series, the default SQL-server based implementation of ASP.NET 2.0's Membership system uses a predefined SQL Server database format that includes tables to support user accounts, membership details, roles, and profiles. When you configure your website to use forms-based authentication through the ASP.NET Website Administration Tool, it automatically creates a SQL Server 2005 database that has this schema and places it in your App_Data folder.

You can customize the default Membership settings - such as allowing passwords with just five characters, or requiring two non-alphanumeric characters - by adding a new Membership provider in the Web.config that uses the same type (SqlMembershipProvider), but uses custom values for properties like minRequiredPasswordLength, minRequiredNonalphanumericCharacters, and so on. When you do this, however, you must also provide a value for the connectionStringName property, which indicates the name of the connection string to use to connect to the SQL database that implements the default Membership schema.

In Part 1 of the article series I show how to specify a custom connection string name, but recently was asked how to have it just use the default ASPNETDB database. The answer: use the connection string name LocalSqlServer. That is, you'd add something like the following to your Web.config file:

<membership defaultProvider="CustomizedProvider">
  <providers>
    <
add name="CustomizedProvider"
         type="System.Web.Security.SqlMembershipProvider"
         connectionStringName="LocalSqlServer"
         minRequiredPasswordLength="5"
         minRequiredNonalphanumericCharacters="0" />
  </
providers>
</
membership>

That's it! In theory, you could also use this connection string to directly reference the ASPNETDB database through code, such as in a SqlDataSource control. However, ideally you will only interact with this database through the API (i.e., the Membership class).

You can see where this connection string name is defined if you look in the machine.config file in the WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG directory. This file contains default settings for all websites on the web server. In there you'll find:

<connectionStrings>
   <
add name="LocalSqlServer"
       
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
        
providerName="System.Data.SqlClient"/>
</
connectionStrings>

When this connection string is used, ASP.NET automatically resolves the substring |DataDirectory| to the executing application's physical path's App_Data folder. (You'll have to look into the bowels of the .NET Framework using Reflector to see where that's done.)

posted on Friday, January 13, 2006 9:09 AM

Feedback

# re: Referencing the ASPNETDB Database 1/17/2006 10:43 AM Atif Aziz

Thought you might like to know that the value of DataDirectory comes from interrogating AppDomain.CurrentDomain.GetData("DataDirectory"). Obviously, it’s not documented (at least not yet) so it shouldn’t be counted on by applications, but it’s still nonetheless good to know for rainy days.

There's some addition information in a post [1] over at the Smart Client Data blog [2].

[1] http://shrinkster.com/b3c
[2] http://blogs.msdn.com/smartclientdata/

Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

My Links

Ads Via DevMavens

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<March 2010>
SMTWTFS
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910

Comment Stats

DayTotal% of Total
Sunday 2056.8%
Monday 42514.1%
Tuesday 51917.2%
Wednesday 55518.4%
Thursday 58019.2%
Friday 54718.1%
Saturday 1886.2%
Total 3019100.0%

Hour1Total% of Total
12:00 AM 782.6%
1:00 AM 812.7%
2:00 AM 682.3%
3:00 AM 822.7%
4:00 AM 692.3%
5:00 AM 1264.2%
6:00 AM 1183.9%
7:00 AM 1816.0%
8:00 AM 1926.4%
9:00 AM 1585.2%
10:00 AM 1886.2%
11:00 AM 1936.4%
12:00 PM 2016.7%
1:00 PM 1846.1%
2:00 PM 1695.6%
3:00 PM 1354.5%
4:00 PM 1153.8%
5:00 PM 1073.5%
6:00 PM 1013.3%
7:00 PM 1073.5%
8:00 PM 923.0%
9:00 PM 882.9%
10:00 PM 913.0%
11:00 PM 953.1%
Total 3019100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 4.97159
Monday 4.80384
Tuesday 4.04477
Wednesday 7.39680
Thursday 6.26676
Friday 5.07466
Saturday 4.78177
Total 5.403019

Hour1 Entry MadeAvg.Total
12:00 AM 5.2937
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 3.8550
8:00 AM 3.72134
9:00 AM 6.06297
10:00 AM 5.63276
11:00 AM 4.22194
12:00 PM 6.16351
1:00 PM 3.09133
2:00 PM 4.89230
3:00 PM 7.64321
4:00 PM 4.00108
5:00 PM 6.07170
6:00 PM 4.64116
7:00 PM 8.95188
8:00 PM 8.63164
9:00 PM 5.00115
10:00 PM 6.31101
11:00 PM 4.5732
Total 5.403019

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles