Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page.EnableSessionState equivalent in ASP.NET MVC

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

like image 505
M4N Avatar asked Sep 02 '10 20:09

M4N


2 Answers

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

like image 80
SamStephens Avatar answered Oct 20 '22 02:10

SamStephens


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.

like image 5
M4N Avatar answered Oct 20 '22 02:10

M4N