SqlMembershipProvider: use my own database as user store database

假装没事ソ 提交于 2019-12-06 01:33:04
aspnet_regsql-C "Data Source=.\SQLEXPRESS;Integrated Security=True;User Instance=True" ...

will generate in database given by connection string

Also you should configure MembershipProvider to work with your database. Just add this to your web.config

<configuration>
  <connectionStrings>
    <add name="SqlServices" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=True;User Instance=True" />
  </connectionStrings>
  <system.web>
    <authentication mode="Forms" >
      <forms loginUrl="login.aspx"
        name=".ASPXFORMSAUTH" />
    </authentication>

    <membership defaultProvider="SqlProvider"
      userIsOnlineTimeWindow="15">
      <providers>
        <add 
          name="SqlProvider" 
          type="System.Web.Security.SqlMembershipProvider" 
          connectionStringName="SqlServices"
          applicationName="MyApplication"
          enablePasswordRetrieval="false"
          enablePasswordReset="true"
          requiresQuestionAndAnswer="true"
          requiresUniqueEmail="false"
          passwordFormat="Hashed"
          maxInvalidPasswordAttempts="5"
          passwordAttemptWindow="10" />
      </providers>
    </membership>
  </system.web>
</configuration>

According to the output from "aspnet_regsql -?", there is a paramter -d that you can use, thus making your command:

 aspnet_regsql -S (local) -E -A -d myDatabase

Alternatively you could call it with the "-sqlexportonly filenamegoes.here" parameter to generate a Sql Script that you can review and then apply to your database:

 aspnet_regsql -S (local) -E -A -sqlexportonly output.sql

The MSDN documentation for SqlMembershipProvider explains how to change where it looks for its database, specifically the line connectionStringName="SqlServices" in the Example.

You can specify the -C <connection string> option instead of the -S (local) option and specify a database name in the connection string. This allows to to run the create scripts on an existing database. See here for the aspnet_regsql options.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!