GroupPrincipal 方法 FindByIdentity 抛出奇怪的异常

GroupPrincipal method FindByIdentity throw strange exception(GroupPrincipal 方法 FindByIdentity 抛出奇怪的异常)
本文介绍了GroupPrincipal 方法 FindByIdentity 抛出奇怪的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试按组名获取所有用户并将其显示在 sharepoint webpart 中.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 {"发生操作错误. "}

DirectoryServicesCOMException {"An operations error occurred. "}

推荐答案

在博客中找到答案:

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 ...
}

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

What#39;s the difference between retrieving WindowsPrincipal from WindowsIdentity and Thread.CurrentPrincipal?(从 WindowsIdentity 和 Thread.CurrentPrincipal 检索 WindowsPrincipal 之间有什么区别?)
How do I find a user#39;s Active Directory display name in a C# web application?(如何在 C# Web 应用程序中查找用户的 Active Directory 显示名称?)
How to use Servicestack Authentication with Active Directory/Windows Authentication?(如何在 Active Directory/Windows 身份验证中使用 Servicestack 身份验证?)
How can I authenticate against Active Directory in Nancy?(如何在 Nancy 中对 Active Directory 进行身份验证?)
How to get a username in Active Directory from a display name in C#?(如何从 C# 中的显示名称获取 Active Directory 中的用户名?)
Oauth 2 token for Active Directory accounts(Active Directory 帐户的 Oauth 2 令牌)