Here is an example. Suppose we want to manage a session after validating a user check, so for this demonstration, I only hardcode the validation of a valid user. Account Login
public ActionResult Login(LoginModel model) { if(model.UserName=="xyz" && model.Password=="xyz") { Session["uname"] = model.UserName; Session.Timeout = 10; return RedirectToAction("Index"); } }
On the index page
public ActionResult Index() { if(Session["uname"]==null) { return Redirect("~/Account/Login"); } else { return Content("Welcome " + Session["uname"]); } }
SignOut Button
Session.Remove("uname"); return Redirect("~/Account/Login");
Vedprakash_comp
source share