0

I have a login form like this :

[HttpPost]
        public ActionResult Login(UserAccount user , [Bind(Include = "ID,NameOfSession")] SessionSave Sessions)
        {
            using (QuestionsDBContext db = new QuestionsDBContext())
            {
                var usr = db.userAccount.Single(u => u.UserName == user.UserName && u.Password == user.Password);
                if (user != null)
                {
                    Session["UserID"] = usr.UserID.ToString();
                    Session["Username"] = usr.UserName.ToString();
                    return RedirectToAction("Index");
                }
                else
                {
                    ModelState.AddModelError("", "Username or Password is wrong");
                }
            }
            return View();
        }

It appears every time I want to go to the index view, as it is coded like this. I want to make it remember all time when I log in at once. I know, I can do it by many ways, but please inform me about possible ways and any further references, that can be useful.

Safayat Zisan
  • 33
  • 1
  • 13
  • You can do this by cookie. you can store id or something else in your cookie and can check. – Ubiquitous Developers Aug 25 '16 at 12:56
  • 1
    1. Do not use the Session store for authentication because a session can be hijacked. 2. Most Authentication frameworks like Asp.Net identity provide built in mechanisms for `remember me`. 3. `Remember Me` is made to automatically authenticate even after they have closed the browser and does not denote getting the authenticated context between requests which is usually standard. My recommendation: Start with Microsoft Identity Framework, this is the current MS recommended framework for authentication and authorization in MVC and you can see full example with a new MVC app in Visual Studio. – Igor Aug 25 '16 at 13:07
  • One last point. Do not try to role (create) your own Authentication / Authorization provider, use an existing framework as these are highly tested, flexible, and much more secure than anything you or I will ever create. – Igor Aug 25 '16 at 13:09
  • Possible duplicate of [Implementing "Remember Me" Feature in ASP.NET MVC](http://stackoverflow.com/questions/5619791/implementing-remember-me-feature-in-asp-net-mvc) – Mohammed Dawood Ansari Aug 25 '16 at 13:35

0 Answers0