MVC3 added a good opportunity to make sessionless controllers using [SessionState(SessionStateBehavior.Disabled)] attribute. That’s great but not flexible because you cannot set session state for each controller method and also you cannot enable it by condition.
Is it possible to enable session state for authenticated users only or by some other custom condition?
I.e. PHP has a great feature.
if (!isset($_SESSION)) session_start();
That would be nice to find something like that
You could override the default controller factory and more specifically the GetControllerSessionBehavior method:
and in
Application_Startreplace the default controller factory with the custom one: