Question

Can I specify a different database than ASPNETDB using SqlMembershipProvider? I am developing a site on a shared host, and have to restrict my data schema to a single provided database.

I was roundly scolded last time I suggested rolling my own authentication code.

Alternatively, is there some other packaged authentication system I could drop in and configure to use an arbitrary database and tables from asp.net?

Was it helpful?

Solution

You can install the ASP.Net Membership Schema to any SQL database by using the aspnet_regsql command line tool.

You can also specify any connection string you'd like for your membership provider. Simply add something like this to your membership declaration in your web.config file:

<connectionStrings>
    <add name="MyConnectionString" connectionString="Database=MyDatabase;Server=xxx;User=xxx;Pwd=xxx;" providerName="System.Data.SqlClient"/>

</connectionStrings> 

<membership defaultProvider="MyProvider">
      <providers>
        <add connectionStringName="MyConnectionString" applicationName="/Test"
    description="MyProvider" name="MyProvider" type="SqlMembershipProvider" />
      </providers>
</membership> 

OTHER TIPS

The previous answer is largely correct, but I had a problem until I fully qualified the "Type" value to be "System.Web.Security.SqlMembershipProvider".

<membership defaultProvider="MyProvider">
  <providers>
    <add connectionStringName="MyProvider"
         applicationName="/Test"
         description="MyProvider"
         name="MyProvider"
         type="System.Web.Security.SqlMembershipProvider" />
  </providers>
</membership>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top