【发布时间】:2014-02-27 01:24:36
【问题描述】:
我有以下代码在我的 MVC3 Web 应用程序中检索给定用户名的 AD 组:
PrincipalContext userDomain = new PrincipalContext(ContextType.Domain, username.Split('\\')[0]);
UserPrincipal user = UserPrincipal.FindByIdentity(userDomain, username);
PrincipalSearchResult<Principal> memberOfGroups = user.GetGroups();
IEnumerator<Principal> memberOfGroupsEnumerator = memberOfGroups.GetEnumerator();
List<string> userADGroups = new List<string>();
try
{
while (memberOfGroupsEnumerator.MoveNext())
{
userADGroups.Add(memberOfGroupsEnumerator.Current.ToString());
}
}
catch
{
// When trying to access AD groups of a different domain, issues can arise at the end of the enumerator. These may be ignored.
}
这在本地工作正常,但是当部署到网络上的另一台机器上时,会出现以下错误:
发生操作错误。
错误的堆栈跟踪:
System.DirectoryServices.DirectoryServicesCOMException (0x80072020):发生操作错误。
在 System.DirectoryServices.DirectoryEntry.Bind(布尔 throwIfFail)
在 System.DirectoryServices.DirectoryEntry.Bind()
在 System.DirectoryServices.DirectoryEntry.get_AdsObject()
在 System.DirectoryServices.PropertyValueCollection.PopulateList()
在 System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry 条目,字符串属性名称)
在 System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
在 System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()
在 System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
在 System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
在 System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()
在 System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext 上下文,类型 principalType,Nullable`1 identityType,字符串 identityValue,DateTime refDate)
在 System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext 上下文,字符串 identityValue)
在 MvcSFIWebSite.Models.User..ctor(字符串用户名)
错误消息相当模糊,我无法弄清楚发生了什么,因为它在本地运行良好。
用于部署的计算机上的 IIS 使用自定义帐户而不是 AppPool 身份。是否应该授予此帐户访问 AD 组目录的任何权限? IIS 中是否需要任何其他设置才能使其正常工作?
任何建议都会非常有帮助。提前致谢。
【问题讨论】:
标签: c# asp.net-mvc-3 iis-7