【发布时间】:2014-03-25 15:38:19
【问题描述】:
我的团队在 VS 2013 中使用 IIS Express 进行调试,在为 AD 组查询 Active Directory 时出现以下错误:
System.DirectoryServices.AccountManagement.dll 中出现“System.Runtime.InteropServices.COMException”类型的异常,但未在用户代码中处理
附加信息:与服务器的多个连接或共享 同一用户使用多个用户名的资源不属于 允许。断开与服务器的所有先前连接或共享 资源,然后重试。
在下面的代码中,错误是由GetAuthorizationGroups() 抛出的。
代码:
public List<String> GetAllADGroups(String userName)
{
List<String> groups = new List<String>();
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, this.Domain, this.LDapUserName, this.LDapPassword);
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, userName);
// error on next line
foreach(Principal group in user.GetAuthorizationGroups().OrderBy(x => x.Name))
{
if (group.ContextType == ContextType.Domain && !String.IsNullOrEmpty(group.Name))
{
groups.Add(group.Name);
}
}
ctx.Dispose();
return groups;
}
由于这个项目在 TFS 中,我有 3 个开发人员从他们的开发服务器上运行此代码。我只在其中一台服务器上收到此错误。在引发此错误的服务器上;当我从 IIS 运行站点时,代码工作正常。所以它让我认为问题出在以下之一:
- IIS Express
- 服务器配置
- VS 2013 配置
感谢任何帮助。
【问题讨论】:
标签: visual-studio c#-4.0 active-directory iis-express asp.net-4.5