tags:

views:

110

answers:

1

Looking at the MVC source today:

public class MvcHandler : IHttpHandler, IRequiresSessionState

why does it need SessionState? Isn't MVC trying to do something RESTful?

I know the reason for using session state in MVC is for transferring some data (can't remember the term but session state can be substituted with other mediums ). I think my real question is:

why can't I write an MVC app and specify and have the option to turn off session state completely?

+3  A: 

It requires it because of TempData. TempData is like ViewData except it will make it to the view and back, once. To accomplish this it needs a cookie.

There's a way to get around it by creating a dummy object, I just can't remember how.

Found it, thanks to Kigg.

public class EmptyTempDataProvider : ITempDataProvider
{
    public IDictionary<string, object> LoadTempData(ControllerContext controllerContext)
    {
        return new Dictionary<string, object>();
    }

    public void SaveTempData(ControllerContext controllerContext, IDictionary<string, object> values)
    {
    }
}

Then you have to create a base controller and derive from it when you create your other controllers.

protected BaseController()
{
    TempDataProvider = new EmptyTempDataProvider();
}

This should allow you to disable session state.

Chad Moran