【问题标题】:Roles are not working角色不工作
【发布时间】:2012-07-22 11:09:29
【问题描述】:

我已经通过 ftp 手动发布了我的 asp.net 网站,一切正常(登录、注册等) 但是角色不起作用,例如:普通用户可以访问仅为管理员创建的页面。

这是我的 web.config:

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="MyConnStrg" connectionString="provider details..etc.."
      providerName="System.Data.SqlClient" />
  </connectionStrings>
    <system.web>
      <roleManager enabled="true" defaultProvider="MyWebsiteTC">
        <providers>
          <add name="MyWebsiteTC"
          type="System.Web.Security.SqlRoleProvider"
          applicationName="/"
          connectionStringName="MyConnStrg" />
        </providers>
      </roleManager>
      <membership defaultProvider="MyWebsiteTCMembershipProvider">
        <providers>
          <add name="MyWebsiteTCMembershipProvider"
          type="System.Web.Security.SqlMembershipProvider"
          connectionStringName="MyConnStrg"
          enablePasswordRetrieval="false"
          enablePasswordReset="true"
          requiresQuestionAndAnswer="true"
          applicationName="/"
          requiresUniqueEmail="true"
          passwordFormat="Hashed"
          maxInvalidPasswordAttempts="5"
          minRequiredPasswordLength="7"
          minRequiredNonalphanumericCharacters="1"
          passwordAttemptWindow="10"
          passwordStrengthRegularExpression=""/>
        </providers>
      </membership>

      <compilation debug="true" targetFramework="4.0" />
      <authentication mode="Forms">
        <forms name=".KKDS"
          timeout="30"
          slidingExpiration="true"
          cookieless="UseCookies"
          defaultUrl="~/Default.aspx"
       />
      </authentication>
    </system.web>
</configuration>

管理文件位于包含此 web.config 的文件夹中:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <customErrors mode="Off"/>
    <authorization>
      <allow roles="Client" />
      <deny users="?"/>
    </authorization>

  </system.web>
</configuration>

为每个用户添加了角色,一切正常,但角色身份验证没有。 我能做什么?

【问题讨论】:

  • 首先你有一个供应商标签打开两次

标签: c# asp.net


【解决方案1】:

我认为应该是:

 <authorization>
    <allow roles="Client" />
    <deny users="*"/>
 </authorization>

因为您希望允许角色为Client 的用户并拒绝任何其他人(而不是拒绝未登录的用户,如在您的 sn-p 中)。

【讨论】:

    【解决方案2】:

    Wiktor Zychla 提出了一个很好的建议。如果该网站在您发布之前正在运行,我认为问题可能与ApplicationName 有关...我为处理ApplicationName 的其他人回答了一个问题。看看这个……

    Going from dev to prod with .net Membership Provider

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-04
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 2013-04-01
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多