启用/禁用每个控制器/操作方法的会话状态
我们正在构建一个 ASP.NET MVC 应用程序,该应用程序将部署在支持缓存等功能的硬件负载平衡器后面。
我们的建议是手动定义负载均衡器应缓存哪些 URL 模式。这对我们来说将是一个相当简单的过程,因为我们有相对静态的“目录”页面,然后是非静态的“订单”页面。
必须避免在缓存页面上使用会话状态,因为整个响应由负载均衡器缓存 - 这包括发送的任何 cookie。
理想情况下,应该有一个属性可以应用于控制器或操作方法,从而允许选择性地使用会话状态,但似乎没有这样的属性。我意识到,如果使用离开“会话区域”,这样的方法会导致会话丢失 - 这很好。
除了重新实现整个 ASP.NET MVC HTTP 控制器...还有什么建议吗?
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在它已从 Future 移至 MVC3。有一个
ControllerSessionState
属性(显然在 MVC3 的最终版本中将被命名为SessionState
),它可以应用于控制器,如下所示:(但在 RC 版本中,您必须使用
ControllerSessionState
This is now moved from Futures into MVC3. There's a
ControllerSessionState
attribute (apparently will be namedSessionState
for the final release of MVC3), which can be applied to a controller, something like this:(But in the RC version, you must use
ControllerSessionState
这包含在 MVC 2 Futures 中。请参阅 http://blogs.msdn .com/rickandy/archive/2009/12/17/session-less-mvc-controller.aspx 了解更多信息。
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.