16

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.)

6

2 Answers 2

20

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

5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.