title: jQuery $.ajax post works perfectly fine on local, but throws 500 error on server
body: <p>I am working on app which should manage custom team structure so when team leaders adds their members I want them to add only login add pull the First name and Last name from AD. It works fine when I run it on local, but I get 500 Internal server error on server.</p>
  
  <p>jQuery:</p>
  
  <pre><code>        var json = { "ldapLogin": ldapLogin };
          var saveAction = $.ajax({
              type: "POST",
              url: manageLdapURL,
              contentType: "application/json; charset=utf-8",
              data: JSON.stringify(json),
              dataType: "json",
              success: function (json) {
                  if (json.Status == 1) {
                      firstName = json.FirstName;
                      lastName = json.LastName;
                      if (!json.isMember) {
                          $(".dialog-confirm-warning").dialog('open');
                      }
                  }
                  else if (json.Status == 2) {
                      $("p .warning").text(json.Message);
                      $(".dialog-user-do-not-exist").dialog('open');
                  }
              },
              error: function (xhr, ajaxOptions, thrownError) {
                  console.log(xhr.status);
                  console.log(thrownError);
                  console.log(xhr.responseText);
              }
          });
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>    [HttpPost]
      [Authorize]
      public JsonResult ManageAgentLdap(string ldapLogin)
      {
          bool isServiceDeskMember = false;
  
          try
          {
              UserPrincipal foundUser = Utility.getUserNameFromLdap(ldapLogin);
  
              if (foundUser != null)
              {
                  ServiceDeskWorgroupsDataContext db2 = new ServiceDeskWorgroupsDataContext();
  
                  bool serviceDeskMembersExist = db2.v_MandaysPortalUserClarifications.Any(l =&gt; l.LDAPLogin == ldapLogin);
                  if (serviceDeskMembersExist)
                  {
                      isServiceDeskMember = true;
                  }
  
                  return Json(new
                  {
                      Status = 1,
                      FirstName = foundUser.GivenName,
                      LastName = foundUser.Surname,
                      isMember = isServiceDeskMember
                  });
              }
          }
          catch (DataException e)
          {
              ModelState.AddModelError("", "Unable to query Active Directory. Try again, and if the problem persists see your system administrator.");
          }
  
          return Json(new { Status = 2, FirstName = "", LastName = "", isMember = isServiceDeskMember });
      }
  </code></pre>
  
  <p>I can post the method getUserNameFromLdap(ldapLogin), but I am quite sure that this is not the problem as it is used elsewhere and works fine.</p>
  
  <p>My idea is that I violate some internal server securities which I am not aware of (I am not yet fully familiar with the .NET MVC yet).</p>
  
  <p>EDIT:</p>
  
  <p>I was finally able to get the error details and it was this:</p>
  
  <pre><code>    [DirectoryServicesCOMException (0x80072020): An operations error occurred.
  ]
      System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +387793
      System.DirectoryServices.DirectoryEntry.Bind() +36
      System.DirectoryServices.DirectoryEntry.get_AdsObject() +31
      System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) +78
      System.DirectoryServices.DirectorySearcher.FindAll() +9
      System.DirectoryServices.ActiveDirectory.Forest.GetDomains() +410
  
      [ActiveDirectoryOperationException: An operations error occurred.
  ]
      System.DirectoryServices.ActiveDirectory.Forest.GetDomains() +738
      System.DirectoryServices.ActiveDirectory.Forest.get_Domains() +38...
  </code></pre>