SqlMembershipProvider: use my own database as a user repository database

I am developing an ASP.NET application with Visual Studio 2008 SP1 and C # . I also use Sql Server 2008 SP1 .

I am trying to add tables created using the command aspnet_regsql -S (local) -E -A mto my own database.

If I run this command, it will create a database ( Aspnetdb ) with four tables. I want to know if there is a command that creates these tables in my own database (e.g. myDatabase ).

And when the tables are created. How to connect authentication to myDatabase ?

thank

+3
source share
3 answers
aspnet_regsql-C "Data Source=.\SQLEXPRESS;Integrated Security=True;User Instance=True" ...

will be generated in the database specified by the connection string

You must also 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>
+4
source

According to the output from aspnet_regsql -? "there is a -d option that you can use, thereby doing your command:

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

Alternatively, you can call it with the "-sqlexportonly filenamegoes.here" parameter to create an Sql Script that you can view and then apply to your database:

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

MSDN SqlMembershipProvider , , , connectionStringName = "SqlServices" .

+4

-C <connection string> -S (local) . . . aspnet_regsql.

+2

Source: https://habr.com/ru/post/1734398/


All Articles