【发布时间】: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