I have a requirement, where I validate user using Windows Authentication. Till there it works perfectly fine. But when I try to redirect to respective controllers
it does nothing.
Below is my code:
public ActionResult ValidateUser(string strUsername, string strPassword)
{
string strReturn = "";
string strDbError = string.Empty;
strUsername = strUsername.Trim();
strPassword = strPassword.Trim();
UserProviderClient ObjUMS = new UserProviderClient();
bool result = ObjUMS.AuthenticateUser(strUsername, strPassword, out strDbError);
Session["isUserAuthenticated"] = result;
if (result == true)
{
Session["isUserOutsideINDomain"] = true;
Session["OutsideINDomainUsername"] = strUsername;
//redirect to respective controller
UMS ObjUMSDATA = new UMS();
string strUserName = "";
string strCurrentGroupName = "";
int intCurrentGroupID = 0;
strUserName = System.Web.HttpContext.Current.User.Identity.Name.Split('\\')[1];
_UMSUserName = strUserName;
if (!string.IsNullOrEmpty(strUserName))
{
List<UMSGroupDetails> lstUMSGroupDetails = null;
List<UMSLocationDetails> lstUMSLocationDetails = null;
ObjUMSDATA.GetUMSGroups(strUserName, out strCurrentGroupName, out intCurrentGroupID, out lstUMSLocationDetails, out lstUMSGroupDetails);
if (strCurrentGroupName != "" && intCurrentGroupID != 0)
{
ViewBag.LoginUserName = strUserName.ToUpper();
ViewBag.CurrentGroupName = strCurrentGroupName;
ViewBag.CurrentGroupID = intCurrentGroupID;
ViewBag.GroupDetails = lstUMSGroupDetails;
ViewBag.LocationDetails = lstUMSLocationDetails;
TempData["Location"] = lstUMSLocationDetails;
TempData["strCurrentGroupName"] = strCurrentGroupName;
TempData.Keep();
if (strCurrentGroupName == "NEIQC_SAP_ENGINEER")
{
return RedirectToAction("Assign","App"); // here its not redirecting properly.
}
else if (strCurrentGroupName == "NEIQC_FIBER_ENGINEER")
{
return RedirectToAction("App", "Certify");
}
else if (strCurrentGroupName == "NEIQC_CMM")
{
return RedirectToAction("App", "Approver");
}
}
else
{
return RedirectToAction("ErrorPage", "UnAuthorize");
}
}
}
else
{
strReturn = "Login UnSuccessful";
}
return Json(strReturn);
}
Why is it not working?
Update
My route config details.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Login", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Assign",
url: "{controller}/{action}/{id}",
defaults: new { controller = "App", action = "Assign", id = UrlParameter.Optional }
);
}
Ajax call
function validateUser() {
var getUserName = $('#txtUsername').val();
var getPassword = $('#txtPassword').val();
// console.log(getUserName);
//console.log(getPassword);
var Values = { "strUsername": getUserName, "strPassword": getPassword };
$.ajax({
url: AppConfig.PrefixURL + "Home/ValidateUser",
dataType: 'json',
type: 'post',
contentType: 'application/json',
data: JSON.stringify(Values),
processData: false,
success: function () {
},
error: function () {
}
});
}