In code bellow i make login for save username and password in cookies client if it is correct username and password
Actually what i need
I need not using cookies to save username and password In place of cookies i need to using User.Identity.IsAuthenticated in place of cookies
How to do that ?
code below working without any problem
I working in visual studio 2015 with asp.net mvc 4
what i try
for login view get I can restore username and password in login if username and password logged before(no problem in that)
- public ActionResult Login()
- {
- UserAccount model = new UserAccount();
- if (Request.Cookies["Login"] != null)
- {
- model.UserName = Request.Cookies["Login"].Values["UserName"];
- model.Password = Request.Cookies["Login"].Values["Password"];
- }
- return View(model);
From my code below i can login if username and password is correct also i can save username and password in cookies(no problem in that) .
- public ActionResult Login(UserAccount user)
- {
- using (ContainerClass db = new ContainerClass())
- {
- var usr = db.userAccount.Where(u => u.UserName == user.UserName && u.Password == user.Password).FirstOrDefault();
-
- if (usr != null)
- {
- FormsAuthentication.SetAuthCookie(user.UserName, user.RememberMe);
- Session["UserID"] = user.UserID.ToString();
- Session["UserName"] = user.UserName.ToString();
-
- if (user.RememberMe)
- {
- HttpCookie cookie = new HttpCookie("Login");
- cookie.Values.Add("UserID", user.UserID.ToString());
- cookie.Values.Add("UserName", user.UserName);
- cookie.Values.Add("Password", user.Password);
- cookie.Expires = DateTime.Now.AddDays(15);
- Response.Cookies.Add(cookie);
-
- }
-
- return RedirectToAction("LoggedIn", "Account");
-
- }
- else
- {
- ModelState.AddModelError("", "Username or Password is wrong");
- }
-
- }
-
- return View(user);
- }