GroupPrincipal方法FindByIdentity抛出怪异常 [英] GroupPrincipal method FindByIdentity throw strange exception

查看:178
本文介绍了GroupPrincipal方法FindByIdentity抛出怪异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让所有用户组的名称和dispalay它在SharePoint web部件。 adGroupName像=CompanyGroup。

I am trying to get all users by group name and dispalay it in sharepoint webpart. adGroupName something like = "CompanyGroup".

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

例外:

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

In order to perform this operation a successful bind must be completed on the connection

这是为什么,什么我做错了?

Why is that and what i am doing wrong?

堆栈跟踪:

       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}

推荐答案

答案被发现在博客:

<一个href="http://sharepoint-tweaking.blogspot.com/2007/12/impersonation-in-aspnet-causes.html">http://sharepoint-tweaking.blogspot.com/2007/12/impersonation-in-aspnet-causes.html

解决方案是使用code:

Solution is to use code:

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

这篇关于GroupPrincipal方法FindByIdentity抛出怪异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆