Database Authentication Setup

Database Authentication Setup

Database

First you need to create an ASP.NET user database on the server using the aspnet_regsql.exe tool.

You can see all the different options and the location of the executable in this MSDN article but the preferred syntax is this:

aspnet_regsql.exe -E -S localhost -A m

-E means you will log in to the SQL Server using your Windows credentials
-S specifies the localhost as the SQL Server address
-A m specifies that we only need the Membership database

The following example shows a complete command line for registering on a different server with a custom database name using an SQL Server authentication.

C:\Windows\Microsoft.NET\Framework\v2.0.50727>aspnet_regsql.exe -S myServer -U sa -P password -A m -d myUserDb

web.config

Now you need to configure the membership provider, especially the database connection string. For all the options see this MSDN article.

Provider Settings

<system.web>
    <membership defaultProvider="sqlMembershipProvider">
        <providers>
            <clear />
                <add
                    name="sqlMembershipProvider" 
                    type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
                    connectionStringName="userDatabase"
                    enablePasswordRetrieval="false"
                    enablePasswordReset="true"
                    requiresQuestionAndAnswer="false"
                    passwordFormat="Hashed"
                    applicationName="ORIGAM" />
        </providers>
    </membership>
</system.web>
 
<connectionStrings>
    <add name="userDatabase" connectionString="Server=serverName;database=scmembers;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>

If you have other applications with which you want to share the user database and passwords, you need to specify the same applicationName.