开发者

Where did aspnetdb.mdf come from in my ASP.NET MVC Application?

I'm new to ASP.NET and have just starting to learn ASP.NET MVC 3. I've started a new ASP.NET MVC 3 project using the default template, which already has most of the membership stuff already configured. Now I'm trying to understand what is really going on behind the scenes.

I've found that default template defines an IMembershipService interface which is implemented by the AccountMembershipService class which basically just wraps a System.Web.Security.MembershipProvider. From the comments in the code is sounds like this abstraction is done to facilitate unit testing.

The default MembershipProvider is set in the Web.config file. My project, which was created from the default template, it is set to the SqlMembershipProvider.

<membership开发者_运维百科>
  <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
         enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
         maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
         applicationName="/" />
  </providers>
</membership>

This references a connection string in the Web.config file, which references a SQL Express database "aspnetdb.mdf".

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

When I first created my project there was no aspnet.mdf file. But after running my app and registering a new user this file was automatically generated tables and all. What's going on here? What creates this file and specified the tables that should be created?


These are created by the SqlMembershipProvider class. If you'd like, you can customize your config file to use a different membership provider or to tell it what existing database to use.

Use this tool to add the appropriate tables, etc to your existing SQL Server installation: http://msdn.microsoft.com/en-us/library/ms229862(v=VS.100).aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜