I want to create a application in which different users have login functionality such as admin, coach and student. Each has there own tasks. So here I want session handling and I am new in asp.net mvc.
Asked
Active
Viewed 1.2k times
0
-
1Please refer [this stackoverflow question](http://stackoverflow.com/questions/13324544/how-to-add-asp-net-membership-provider-in-a-empty-mvc-4-project-template) – Hiren Kagrana Jul 25 '14 at 05:02
1 Answers
2
Here is a Example. Say we want to manage session after checking user validation, so for this demo only I am hard coding checking valid user. On 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 Index Page
public ActionResult Index()
{
if(Session["uname"]==null)
{
return Redirect("~/Account/Login");
}
else
{
return Content("Welcome " + Session["uname"]);
}
}
On SignOut Button
Session.Remove("uname");
return Redirect("~/Account/Login");
Vedprakash_Comp
- 86
- 3