2

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 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.

Paul
  • 1,519
  • 1
  • 16
  • 26
  • this link will lead you to a Multi-Part Article which covers all about users creation, membership and authentication : http://www.asp.net/web-forms/tutorials/security/membership/creating-the-membership-schema-in-sql-server-cs –  Jan 12 '12 at 18:49
  • Thanks Abd, I'll keep a note of that site. – Paul Feb 27 '12 at 10:21

1 Answers1

2

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>
Barry
  • 2,053
  • 3
  • 17
  • 28
  • Thanks Barry. I was already looking at a tutorial on ASP.net which later gave this, so I should have carried on... – Paul Apr 14 '11 at 13:23
  • You also need to create the schema [manually](http://stackoverflow.com/questions/2165908/could-not-find-stored-procedure-dbo-aspnet-checkschemaversion). – doekman Apr 08 '14 at 08:27