【问题标题】:ASP.NET Role Manager Feature Has Not Been EnabledASP.NET 角色管理器功能尚未启用
【发布时间】:2011-07-07 15:36:16
【问题描述】:

我正在尝试在我的 asp.net 主页中创建一个例程,以查看当前用户是否是 Windows 域组的成员。该网站托管在 IIS 中,可通过我们的内部网查看。

GlenFerrieLive 在之前的帖子中列出了这段代码(我想使用它):

    UserName = System.Environment.UserName

    If Roles.IsUserInRole(UserName, "MyDomain\MyGroup") Then
        Dim UserExists As Boolean = True
    End If

在尝试该代码时,我收到了上述错误。所以我在我的 Web.config 中插入了 roleManager 标记,如下所示:

<roleManager enabled="true" cacheRolesInCookie="true" defaultProvider="ActiveDirectoryMembershipProvider" cookieName=".ASPXROLES" cookiePath="/" cookieTimeout="480" cookieRequireSSL="false" cookieSlidingExpiration="true" createPersistentCookie="false" cookieProtection="All" />

问题是,现在我收到配置错误“找不到默认角色提供程序”。

我该如何解决这个问题?我只需要查看当前用户是否存在于特定的域组中。

任何帮助将不胜感激。

谢谢,

杰森

【问题讨论】:

    标签: asp.net vb.net security membership roleprovider


    【解决方案1】:

    查看此页面:http://msdn.microsoft.com/en-us/library/ff648345.aspx

    你需要在你的 webconfig 中指定默认角色提供者指向的位置

    <connectionStrings>
      <add name="ADConnectionString" 
       connectionString=
        "LDAP://domain.testing.com/CN=Users,DC=domain,DC=testing,DC=com" />
    </connectionStrings>
    
    <system.web>
     ...
     <membership defaultProvider="MembershipADProvider">
      <providers>
        <add
          name="MembershipADProvider"
          type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, 
                Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
                    connectionStringName="ADConnectionString" 
                    connectionUsername="<domainName>\administrator" 
                    connectionPassword="password"/>
       </providers>
     </membership>
     ...
    </system.web>
    

    【讨论】:

      【解决方案2】:

      我最终使用了这个:

      Private Function ValidateActiveDirectoryLogin(ByVal Domain As String, ByVal Username As String, ByVal Password As String) As Boolean
          Dim Success As Boolean = False
          Dim Entry As New System.DirectoryServices.DirectoryEntry("LDAP://" & Domain, Username, Password)
          Dim Searcher As New System.DirectoryServices.DirectorySearcher(Entry)
          Searcher.SearchScope = DirectoryServices.SearchScope.OneLevel
          Try
              Dim Results As System.DirectoryServices.SearchResult = Searcher.FindOne
              Success = Not (Results Is Nothing)
          Catch
              Success = False
          End Try
          Return Success
      End Function 
      

      当它在我的 web.config 中时,它就像一个魅力:

          <authentication mode="Windows"/>
      
          <roleManager enabled="true" cacheRolesInCookie="true" defaultProvider="AspNetWindowsTokenRoleProvider" cookieName=".ASPXROLES" cookiePath="/" cookieTimeout="480" cookieRequireSSL="false" cookieSlidingExpiration="true" createPersistentCookie="false" cookieProtection="All" />
      

      【讨论】:

        猜你喜欢
        • 2011-04-21
        • 2019-04-21
        • 1970-01-01
        • 2014-05-10
        • 2013-08-25
        • 2013-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多