With ASP.NET WebForms it is possible to set the session state mode in the page directive:
<%@ Page EnableSessionState="true|false|ReadOnly" %>
Is the same configuration also possible in ASP.NET MVC (e.g. per controller or per action) and if so, how?
(In other words: can I disable or set to read-only session state per controllers/actions? I assume having the session state read/write will result in some overhead, so it might be useful if session state could be turned off if not required.)
The ASP.NET MVC 3 equivalent to this appears to be the SessionState attribute, which you apply at the controller level - e.g.
[SessionState(SessionStateBehavior.ReadOnly)]
See http://msdn.microsoft.com/en-us/library/system.web.mvc.sessionstateattribute.aspx for more info.
Thanks to https://stackoverflow.com/a/4235006/372926
It seems that with ASP.NET MVC 3 it will be possible to have session-less controllers, e.g. see ScottGu's blog post or this post by Keith Dahlby.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With