jQuery $.ajax post works perfectly fine on local, but throws 500 error on server

0

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.

jQuery:

        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);
            }
        });

Controller:

    [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 => 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 });
    }

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.

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

EDIT:

I was finally able to get the error details and it was this:

    [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...
jquery
asp.net-mvc
asked on Stack Overflow May 27, 2015 by Bohuslav Sys • edited Nov 1, 2015 by pnuts

1 Answer

0

make sure that 'System.Web.Extensions.dll' is there in your bin folder.

answered on Stack Overflow May 27, 2015 by Spider man

User contributions licensed under CC BY-SA 3.0