【问题标题】:GroupPrincipal method FindByIdentity throw strange exceptionGroupPrincipal 方法 FindByIdentity 抛出奇怪的异常
【发布时间】:2011-11-02 19:57:12
【问题描述】:

我正在尝试按组名获取所有用户并将其显示在 sharepoint webpart 中。 adGroupName 类似于 = "CompanyGroup"。

GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, adGroupName);

例外:

为了执行此操作,必须在连接上完成成功的绑定

为什么会这样,我做错了什么?

堆栈跟踪:

       at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.PropertyValueCollection.PopulateList()
   at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
   at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
   at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()
   at System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
   at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
   at System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()
   at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate)
   at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue)
   at System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue)
   at NewCo.Intranet.Common.DataAccess.ADUserManager.GetUserForGroup(String adGroupName, Boolean recursive)
   at NewCo.Intranet.Common.DataAccess.ADUserManager.GetMemberForCurrentSite()
   at NewCo.Intranet.Components.WebParts.ADGroupMembers.ADGroupMembersUserControl.Page_Load(Object sender, EventArgs e)

DirectoryServicesCOMException {“发生操作错误。\r\n”}

【问题讨论】:

  • 您确定异常来自这一行吗?你能发布堆栈跟踪吗?

标签: c# asp.net .net sharepoint-2010 active-directory


【解决方案1】:

答案在博客中找到:

http://sharepoint-tweaking.blogspot.com/2007/12/impersonation-in-aspnet-causes.html

解决方法是使用代码:

using (HostingEnvironment.Impersonate()) {
     // This code runs as the application pool user
     DirectorySearcher searcher ...
}

【讨论】:

  • 太棒了!节省了我很多时间!
  • 谢谢!这有助于我在调用 Principal.FindByIdentity() 时修复 DirectoryServicesCOMException。
【解决方案2】:

你是否使用这样的东西来获取你的上下文?

/* Retreiving a principal context
*/
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "MachineIP:389", "dc=dom,dc=fr", "jpb", "root.123");

您可以将 MachineIP 替换为您的域或您的 DC 之一的 DNS 名称。

【讨论】:

    猜你喜欢
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-09
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    相关资源
    最近更新 更多