Session management is simple. Session object is available inside MVC controller and in HttpContext.Current.Session
. It is the same object. Here is a basic example of how to use Session:
Write
Session["Key"] = new User("Login"); //Save session value
Read
user = Session["Key"] as User; //Get value from session
Answering your question
if (Session["Key"] == null){
RedirectToAction("Login");
}
Check out Forms Authentication to implement highly secure authentication model.
UPDATE: For newer versions of ASP.NET MVC you should use ASP.NET Identity Framework. Please check out this article.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…