小编use*_*084的帖子

错误:System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity中出现"操作错误"

我有以下代码来检索我的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.

}
Run Code Online (Sandbox Code Playgroud)

这在本地工作正常,但当部署到网络上的另一台机器上时出错,出现以下错误:

发生了操作错误.

错误的堆栈跟踪:

System.DirectoryServices.DirectoryServicesCOMException(0x80072020):发生操作错误.
在System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
的System.DirectoryServices.DirectoryEntry.Bind()
处于System.DirectoryServices.DirectoryEntry.get_AdsObject()
处于System.DirectoryServices.PropertyValueCollection.PopulateList()
的System.DirectoryServices.PropertyValueCollection ..
System.DirectoryServices.AccountManagement
上System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
的System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()
中的System.DirectoryServices.PropertyCollection.get_Item (String propertyName)上的ctor(DirectoryEntry条目,String propertyName).PrincipalContext.Initialize()
在System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() …

c# iis-7 asp.net-mvc-3

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

asp.net-mvc-3 ×1

c# ×1

iis-7 ×1