[HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult CreateLogin(LoginCreateModel objSubmit) { if(objSubmit.btnSubmit == "Create") { ViewBag.Message = "Details saved successfully"; } return View(objSubmit); } [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult Login(Login login) { if (ModelState.IsValid) { bool success = WebSecurity.Login(login.username, login.password, false); var UserID = GetUserID_By_UserName(login.username); var LoginType = GetRoleBy_UserID(Convert.ToString(UserID)); if (success == true) { if (string.IsNullOrEmpty(Convert.ToString(LoginType))) { ModelState.AddModelError("Error", "Rights to User are not Provide Contact to Admin"); return View(login); } else { Session["Name"] = login.username; Session["UserID"] = UserID; Session["LoginType"] = LoginType; if (Roles.IsUserInRole(login.username, "Admin")) { return RedirectToAction("AdminDashboard", "Dashboard"); } else { return RedirectToAction("UserDashboard", "Dashboard"); } } } else { ModelState.AddModelError("Error", "Please enter valid Username and Password"); return View(login); } } else { ModelState.AddModelError("Error", "Please enter Username and Password"); return View(login); } } namespace eNtsaPortalWebsiteProject.Models { public class LoginCreateModel { [Required] [StringLength(100,ErrorMessage = "The {0} must be least {2} characters long", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Password")] public string password { get; set; } [Required] public string username { get; set; } public string btnSubmit { get; set; } } }
null
GetUserID_By_UserName
GetRoleBy_UserID
if (success)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)