title: C# Active Directory PrincipalContext / UserPrincipal.IsMemberOf error
body: <p>So I have a question I'm honestly not quite sure how to ask. Essentially I have a bit of code that works fantastically on my local machine when I run it. Once I publish it to our development web server, it fails. I'm not sure if it's an IIS setup issue, web.config issue or a coding issue. </p>
  
  <p>Here's the snippet of code</p>
  
  <pre><code>    bool isMember = false;
  
      PrincipalContext ADDomain = new PrincipalContext(ContextType.Domain);
      UserPrincipal user = UserPrincipal.FindByIdentity(ADDomain, userID);
  
      if (user.IsMemberOf(ADDomain, IdentityType.Name, groupName.Trim()))
      {
          isMember = true;
      }
  
      return isMember;
  </code></pre>
  
  <p>Where I pass in a user name and a group and it tells me if that user’s a member in that group. No problem. Works great on my machine. I went to publish that code to the webserver and it fails when it hits the line</p>
  
  <pre><code>UserPrincipal user = UserPrincipal.FindByIdentity(ADDomain, userID); 
  </code></pre>
  
  <p>it throws this error:</p>
  
  <blockquote>
    <p>[DirectoryServicesCOMException (0x80072020): An operations error occurred.]<br>
    System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +788<br>
    System.DirectoryServices.DirectoryEntry.Bind() +44<br>
    System.DirectoryServices.DirectoryEntry.get_AdsObject() +42<br>
    System.DirectoryServices.PropertyValueCollection.PopulateList() +29<br>
    System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry
    entry, String propertyName) +63<br>
    System.DirectoryServices.PropertyCollection.get_Item(String propertyName) +163
        System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()
    +521217<br>
    System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
    +51<br>
    System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
    +141<br>
    System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()
    +42<br>
          System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext
    context, Type principalType, Nullable`1 identityType, String
    identityValue, DateTime refDate) +29<br>
    System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext
    context, String identityValue) +95<br>
    Cosmic.Web.Login.btnSubmit_Click(Object sender, EventArgs e) in C:\cosmic\Cosmic.Web\Login.aspx.cs:79<br>
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154<br>
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691</p>
  </blockquote>
  
  <p>Any ideas where this could be failing?</p>