public HttpResponseMessage Authenticate(string username, string password) { var obj = new ResponseModel(); string adPath = "LDAP://172.20.82.57,DC=urbanunit,DC=gov,DC=pk"; // "basitkhan", "Abc!2345" LdapAuthentication adAuth = new LdapAuthentication(adPath); try { if (true == adAuth.IsAuthenticated1("LDAP://172.20.82.57/OU=UrbanUnit,DC=urbanunit,DC=gov,DC=pk", username, password)) { //// Retrieve the user's groups string groups = adAuth.GetGroups("LDAP://172.20.82.57/OU=UrbanUnit,DC=urbanunit,DC=gov,DC=pk", username, password); var aduser = GetActiveDirectoryUserInfo(username, password); aduser.Groups = groups; obj.status = "200"; obj.message = "Login successfully"; obj.data = aduser; } else { //ViewBag.Error = "Authentication failed, check username and password."; obj.status = "400"; obj.message = "Authentication failed, check username and password."; } } catch (Exception ex) { //ViewBag.Error = "Error authenticating. " + ex.Message; obj.status = "500"; obj.message = "Error authenticating. " + ex.Message; } return(Request.CreateResponse(HttpStatusCode.OK, obj)); }