public ActionResult SubmitLogin(UserAccount obj) { if (ModelState.IsValid) { ReportsBLL Bll = new ReportsBLL(); var isValid = Bll.IsValidUser(obj.UserID, obj.Password); if (isValid) { Session["UserId"] = obj.UserID; FormsAuthentication.SetAuthCookie(obj.UserID, obj.RememberMe); //use RememberMe checkbox to decide if saving UserID or not if (obj.RememberMe) { HttpCookie cookie = new HttpCookie("Login"); cookie.Values.Add("UserID", obj.UserID); cookie.Expires = DateTime.Now.AddDays(15); Response.Cookies.Add(cookie); } else { HttpCookie cookie = new HttpCookie("Login"); cookie.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(cookie); } return(RedirectToAction("Product", "Product")); } ViewData["ErrorMessage"] = "UserID or Password is incorrect"; return(View("Login")); } else { return(View("Login")); } }