ASP.Net & SessionState

Looking at the source of MVC today:

public class MvcHandler: IHttpHandler, IRequiresSessionState

Why do I need a SessionState? Isn't MVC trying to do something RESTful?

I know that the reason for using session state in MVC is to transfer some data (cannot remember the term, but the session state can be replaced by other environments). I think my real question is:

why can't I write an MVC application and point and be able to completely disable session state?

+3
source share
1 answer

It requires this because of TempData. TempData is similar to ViewData, except that one day it will be displayed in the view and vice versa. To do this, he needs a cookie.

, , , .

, 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)
    {
    }
}

.

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

.

+3

Source: https://habr.com/ru/post/1703832/


All Articles