What I want is, I have written a function for Validating user login credentials on server side. So what I am not getting is, I want to prompt a message if user has entered a invalid credentials.
Below is the Code for Validation.
public ActionResult ValidateUser()
{
string strUsername = Convert.ToString(Request.Form["txtUsername"]);
string strPassword = Convert.ToString(Request.Form["txtPassword"]);
// return RedirectToAction("Assign","App");
string strReturn = "";
string strDbError = string.Empty;
strUsername = strUsername.Trim();
strPassword = strPassword.Trim();
string strUserName = "";
string strCurrentGroupName = "";
int intCurrentGroupID = 0;
string controller = "";
string action = "";
UserProviderClient ObjUMS = new UserProviderClient();
bool result = ObjUMS.AuthenticateUser(strUsername, strPassword, out strDbError);
Session["isUserAuthenticated"] = result;
try
{
if (result == true)
{
Session["isUserOutsideINDomain"] = true;
Session["OutsideINDomainUsername"] = strUsername;
//redirect to respective controller
UMS ObjUMSDATA = new UMS();
//strUserName = System.Web.HttpContext.Current.User.Identity.Name.Split('\\')[1];
strUserName = strUsername;
_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["LoginUserName"] = strUserName.ToUpper();
Session["LoginUserName"] = strUsername.ToUpper();
TempData["Location"] = lstUMSLocationDetails;
Session["strCurrentGroupName"] = strCurrentGroupName;
TempData["strCurrentGroupName"] = strCurrentGroupName;
TempData.Keep();
}
else
{
return RedirectToAction("Error", "Shared");
//action = "ErrorPage"; controller = "UnAutherized";
TempData["strLoginErrorInfo"] = "Invalid Username or Password";
TempData.Keep();
}
}
}
if (strCurrentGroupName == "SAP Executive")
{
action = "Assign"; controller = "App";
}
else if (strCurrentGroupName == "Maintenance Lead")
{
//return RedirectToAction("App", "Certify");
action = "Certify"; controller = "App";
}
else if (strCurrentGroupName == "NEIQC CMM")
{
//return RedirectToAction("App", "Approver");
action = "Approver"; controller = "App";
}
}
catch (Exception ex)
{
ApplicationLog.Error("Error", "ValidateUser", ex.Message);
}
return RedirectToActionPermanent(action, controller);
}
Please suggest where I can prompt in my above code.
return Json("Invalid Credentials", JsonRequestBehavior.AllowGet);if you are using AJAX to post to your function. If you are using a model binding, you can useModelState.AddModelError("Error", "Invalid Credentials"); return View(viewModel);