C# How to change default forms authentication database?
I'm in the process of creating a forms authentication based site, and having never needed to do authentication before, I'm a bit stuck.
I have a stock ASP.NET web app fresh from the wizard in VS2010 to test with. I've followed the steps here http://msdn.microsoft.com/en-us/library/879kf95c.aspx to get a working authenticated site.
I have also used aspnet_regsql.exe to create the necessary tables in a fresh database which will be used for开发者_StackOverflow the app data as well as authentication.
What I'm now stuck on is how do I tell the app that it should point at the new database, not the one it created in App_Data...
Any help would be much appreciated.
Thanks, Paul.
Taken from MSDN. Provide the connection string to the database you're going to use, then configure the membership provider to use that connection string.
<configuration>
<connectionStrings>
<add name="MySqlConnection" connectionString="Data
Source=MySqlServer;Initial Catalog=aspnetdb;Integrated
Security=SSPI;" />
</connectionStrings>
<system.web>
<authentication mode="Forms" >
<forms loginUrl="login.aspx"
name=".ASPXFORMSAUTH" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add
name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MySqlConnection"
applicationName="MyApplication"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="true"
passwordFormat="Hashed" />
</providers>
</membership>
</system.web>
</configuration>
精彩评论