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.

2
  • this link will lead you to a Multi-Part Article which covers all about users creation, membership and authentication : asp.net/web-forms/tutorials/security/membership/… Commented Jan 12, 2012 at 18:49
  • Thanks Abd, I'll keep a note of that site. Commented Feb 27, 2012 at 10:21

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Barry. I was already looking at a tutorial on ASP.net which later gave this, so I should have carried on...
You also need to create the schema manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.