Я добавил проверку и проверку, где, если пользователь добавляет неверное имя пользователя и пароль, система выдает сообщение.
Но я хочу удалить это сообщение, если пользователь снова идет ипопробуйте ввести имя пользователя и пароль.В настоящее время сообщение не исчезает.
Код:
[HttpPost]
[ValidateInput(false)]
public ActionResult ValidateUser() {
string strUsername = Sanitizer.GetSafeHtmlFragment(Convert.ToString(Request.Form["txtUsername"]));
string strPassword = Sanitizer.GetSafeHtmlFragment(Convert.ToString(Request.Form["txtPassword"]));
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 = false;
if (strUsername != "" || strPassword != "") {
result = ObjUMS.AuthenticateUser(strUsername, strPassword, out strDbError);
try {
if (result == true) {
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();
TempData["Location"] = lstUMSLocationDetails;
TempData["strCurrentGroupName"] = strCurrentGroupName;
TempData.Keep();
} else {
ModelState.AddModelError(string.Empty, "You are not registered. Please register first.");
return View("Login");
}
}
}
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";
} else {
ModelState.AddModelError(string.Empty, "Invalid Username and password");
return View("Login");
}
} catch (Exception ex) {
ApplicationLog.Error("Error", "ValidateUser", ex.Message);
}
} else {
ModelState.AddModelError(string.Empty, "Invalid Username and password");
return View("Login");
}
//Session["isUserAuthenticated"] = result;
return RedirectToActionPermanent(action, controller);
}
HTML:
<div class="loginForm" id="loginForm" ng-controller="UserSelection">
@using (Html.BeginForm("ValidateUser", "Home", FormMethod.Post)) {
<div class="formGroup hide1">
<input type="text" id="txtUsername" class="formInput" name="txtUsername" ng-model="LoginUserName" />
<span class="focusInput" data-placeholder="Username"></span>
</div>
<div class="password formGroup hide1">
<input type="password" id="txtPassword" class="formInput" name="txtPassword" ng-model="LoginPassword" />
<span class="focusInput" data-placeholder="Password"></span>
</div>
<div class="submit formGroup hide1">
@*<button type="button" id="submit" onclick="return validateUser();">Submit</button>*@
<button type="submit" id="submit" ng-disabled="(!LoginUserName||!LoginPassword)" onclick="return submitLogin();" class="loginUser"><i class="fa fa-refresh fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span> Submit</button>
</div>
<div class="error">
@Html.ValidationSummary(false, "", new { @class = "text-danger " })
</div>
<div class="ums">
<a href="#" target="_blank" title="Contact Jio.GISOperations@ril.com for registration and support.">Register</a>
</div>
@*
<div class="ums"><a href="#" target="_blank">Register</a></div>*@ }
</div>
Выше мой код, пожалуйста, предложите, где я ошибаюсь.