启用/禁用每个控制器/操作方法的会话状态

发布于 2024-08-21 16:11:25 字数 367 浏览 2 评论 0原文

我们正在构建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

開玄 2024-08-28 16:11:25

现在它已从 Future 移至 MVC3。有一个 ControllerSessionState 属性(显然在 MVC3 的最终版本中将被命名为 SessionState),它可以应用于控制器,如下所示:(

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

但在 RC 版本中,您必须使用ControllerSessionState

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

蝶…霜飞 2024-08-28 16:11:25

这包含在 MVC 2 Futures 中。请参阅 http://blogs.msdn .com/rickandy/archive/2009/12/17/session-less-mvc-controller.aspx 了解更多信息。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文