【问题标题】:AD Groups for Windows UserWindows 用户的 AD 组
【发布时间】:2015-04-03 20:30:23
【问题描述】:

我有一个配置为使用 Windows 身份验证的 asp.net MVC 应用程序。我正在尝试使用这个从 UserPrincipal 获取组。

UserPrincipal.Current.GetGroups()

这在从 Visual Studio 运行时可以正常工作,但在 IIS 上托管时会失败。应用程序池配置为集成管道和网络服务标识。抛出以下错误:

无法将“System.DirectoryServices.AccountManagement.GroupPrincipal”类型的对象转换为“System.DirectoryServices.AccountManagement.UserPrincipal”类型。”

我尝试模拟代码

WindowsIdentity identity = (WindowsIdentity)HttpContext.Current.User.Identity;

using (WindowsImpersonationContext wic = identity.Impersonate())
{
     PrincipalContext context = new PrincipalContext(ContextType.Domain, "DOMAIN NAME");
     UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "User Name");

}

FindByIdentity 抛出错误。

000004DC: LdapErr: DSID-0C0906E8,注释:为了执行此操作,必须在连接上完成成功的绑定。数据 0,v1db1

如何从 AD 获取当前用户组?

【问题讨论】:

  • 你是怎么解决这个问题的?

标签: c# asp.net asp.net-mvc windows-authentication directoryservices


【解决方案1】:

我最终遇到了这个问题,因为我不小心将 IIS 站点的身份验证类型设置错了。我删除了“匿名身份验证”,并将其设置为仅启用了“asp.net 身份验证”和“Windows 身份验证”,然后错误就消失了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    相关资源
    最近更新 更多