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

发布于 2024-12-27 10:51:49 字数 2065 浏览 3 评论 0原文

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

我已使用 aspnet_regsql.exe 将会员数据库添加到我网站的 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>

如果可以使用数据库上的 ASP.Net 配置工具保存、修改和删除用户,那么我希望角色能够做同样的事情吗?我缺少哪一步?

I'm learning about how to manipulate the Membership class.

I have added the Membership database to my website's SQL Database using aspnet_regsql.exe and so far I can list and add users without a problem. However, I decided to add some roles using the ASP.Net Configuration Tool. The roles were added, but did not show up in the aspnet_Roles table of my SQL database.

I have since noticed ASPNETDB.MDF in my VS2010 App_Data folder for the website in question and the Roles are appearing in there. The users are not in that database but are in the SQL DB configured in my web.config file:

<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>

If the users can be saved, modified and deleted using the ASP.Net Configuration Tool on my database, then I would have expected the Roles to do the same? What step am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

任性一次 2025-01-03 10:51:49

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

<roleManager enabled="true" defaultProvider="TheRoleProvider">
 <providers>
  <clear/>
   <add name="TheRoleProvider" 
        type="System.Web.Security.SqlRoleProvider"
        connectionStringName="myConnString" 
        applicationName="/"/>
 </providers>
</roleManager>

You need to set the role provider configuration, like your membership provider

<roleManager enabled="true" defaultProvider="TheRoleProvider">
 <providers>
  <clear/>
   <add name="TheRoleProvider" 
        type="System.Web.Security.SqlRoleProvider"
        connectionStringName="myConnString" 
        applicationName="/"/>
 </providers>
</roleManager>
云柯 2025-01-03 10:51:49

您缺少 roleManager。这是一个例子:

<roleManager enabled="true">
    <providers>
        <clear />
        <add connectionStringName="myConnString" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
        <add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
    </providers>
</roleManager>

You are missing roleManager. Here is an example:

<roleManager enabled="true">
    <providers>
        <clear />
        <add connectionStringName="myConnString" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
        <add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
    </providers>
</roleManager>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文