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);
Exception:
In order to perform this operation a successful bind must be completed on the connection
Why is that and what i am doing wrong?
stack trace:
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 {“An operations error occurred.rn”}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Answer was found in blog:
http://sharepoint-tweaking.blogspot.com/2007/12/impersonation-in-aspnet-causes.html
Solution is to use code:
using (HostingEnvironment.Impersonate()) {
// This code runs as the application pool user
DirectorySearcher searcher ...
}
Method 2
Do you use something like this to get your context ?
/* Retreiving a principal context */ PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "MachineIP:389", "dc=dom,dc=fr", "jpb", "root.123");
Where you can replace MachineIP by the DNS name of your domain or one of you DC.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0