ASP.Net成员:角色保存在不同的数据库中

Com*_*umb 1 c# asp.net asp.net-membership

我正在学习如何操纵Membership类.

我已使用aspnet_regsql.exe将Membership数据库添加到我的网站的SQL数据库中,到目前为止,我可以列出并添加用户没有问题.但是,我决定使用ASP.Net配置工具添加一些角色.角色已添加,但未显示在我的SQL数据库的aspnet_Roles表中.

我已经注意到我的VS2010 App_Data文件夹中的ASPNETDB.MDF用于相关网站,并且角色出现在那里.用户不在该数据库中,而是在我的web.config文件中配置的SQL DB中:

<configuration> 
    <connectionStrings>
        <add name="myConnString" connectionString="Data Source=SQLDB;Initial Catalog=myDatabase;User ID=myUser;Password=myPassword" providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.web>
        <authentication mode="Forms" />
        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            </assemblies>
        </compilation>
        <machineKey validationKey="LOTSOFNUMBERS"
        decryptionKey="MORENUMBERS" validation="SHA1" decryption="AES"/>
        <membership  defaultProvider="SqlProvider">
            <providers>
                <clear/>
                <add name="SqlProvider"
                connectionStringName="myConnString"
                type="System.Web.Security.SqlMembershipProvider"
                applicationName="myApp"
                requiresUniqueEmail="true"
                minRequiredPasswordLength="8"
                minRequiredNonalphanumericCharacters="0"
                requiresQuestionAndAnswer="false"
                passwordFormat="Encrypted"
                enablePasswordRetrieval="true"
                />
            </providers>
        </membership>
        <roleManager enabled="true" />
        <pages theme="myTheme">
        </pages>
        <authorization>
            <deny users="?"/>
        </authorization>
    </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

如果可以使用我的数据库上的ASP.Net配置工具保存,修改和删除用户,那么我原本期望角色也这样做?我错过了什么步骤?

Fab*_*Luz 5

您需要设置角色提供程序配置,例如您的成员资格提供程序

<roleManager enabled="true" defaultProvider="TheRoleProvider">
 <providers>
  <clear/>
   <add name="TheRoleProvider" 
        type="System.Web.Security.SqlRoleProvider"
        connectionStringName="myConnString" 
        applicationName="/"/>
 </providers>
</roleManager>
Run Code Online (Sandbox Code Playgroud)