Enable / disable session state per controller / action method

孤街醉人 提交于 2019-11-26 14:14:27

问题


We are building an ASP.NET MVC application which will be deployed behind a hardware load balancer that supports, among other things, caching.

Our proposal is to manually define which URL patterns should be cached by the load balancer. This will be quite an easy process for us as we have 'catalogue' pages which are relatively static, then 'order' pages which are not.

Must avoid using session state on cached pages, as the entire response is cached by the load balancer - this includes any cookies that are sent.

Ideally there would be an attribute which can be applied to controllers or action methods which allows selective use of session state, but there doesn't appear to be one. I realise that an approach like this would result in lost sessions if the use leaves the 'session zone' - that's fine.

Other than re-implementing the entire ASP.NET MVC HTTP controller... any suggestions?

Thanks in advance.


回答1:


This is included in MVC 2 Futures. See http://blogs.msdn.com/rickandy/archive/2009/12/17/session-less-mvc-controller.aspx for more info.




回答2:


This is now moved from Futures into MVC3. There's a ControllerSessionState attribute (apparently will be named SessionState for the final release of MVC3), which can be applied to a controller, something like this:

[SessionState(SessionStateBehavior.Disabled)]
public class MyController : Controller
{
 ...

(But in the RC version, you must use ControllerSessionState



来源:https://stackoverflow.com/questions/2250940/enable-disable-session-state-per-controller-action-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!