@Blog.Author(Nandip Makwana) .LearningExperience(ASP.NET, ASP.NET MVC, IIS, jQuery & Technology Surrounding it...)

December 8, 2012 comment

ASP.NET MVC: SessionState action filter

ASP.NET MVC: SessionState

SessionState attributes specify the session state behavior for the controller. We can use this attribute only with controller. Sometime we require that we want to disable session state for specific controller, in this case we can apply SessionState attribute in ASP.NET MVC controller. Please note that this attribute control the session state behavior for the specific controller and not session state mode for entire application.

Attribute Usage: Controller

Sample Code:

public class HomeController : Controller
    public ActionResult About()
        Session["key"] = "value";
        return View();

In the above example we have disabled session state for Home controller so now whenever we try to access session from within any action method of this controller, then it will throw an Object reference not found exception. Following are list of session state behavior with this attribute.

  • Default
  • Required
  • ReadOnly
  • Disabled

Check out ASP.NET MVC: Action filter series post to read about other available  action filters.

You can follow me on twitter for latest link and update on ASP.NET & MVC.

comments powered by Disqus

Featured Content

Resources & Tools

About Nandip Makwana

Nandip Makwana is passionate about digital world and web. He completed his Masters in Computer Application in June 2011. Currently he is working as a Software Engineer. He has shown great promise and command over ASP.NET and technologies surrounding it during his academic years and professorial life...continue reading