ASP.NET MVC:按 OutputCache 属性中的 HTTP 状态代码进行过滤/变化
在我正在编写的 ASP.NET MVC 站点中,我正在构建一个由 HttpModule 路由到的通用错误操作, 遵循本教程。在此操作中,我将返回与应用于 HttpModule 内响应的状态代码相对应的视图(执行此操作后,模块将请求传输到相关操作)。
这一切都很好,只是我想实现缓存。我不想在没有过滤/变化的情况下使用 OutputCache
属性,因为这意味着页面将被缓存一次。我希望为每个可能的状态代码缓存一次页面。
是否可以通过 OutputCacheAttribute
的属性以某种方式进行过滤/变化,以便单独缓存每个 Response.StatusCode?
In the ASP.NET MVC site that I'm writing, I'm building a generic Error Action that is routed to by an HttpModule, following this tutorial. In this Action, I will return a View corresponding to the status code that is applied to the response inside the HttpModule (after doing this, the module transfers the request over to the Action in question).
That's all good, except that I want to implement caching. I don't want to use the OutputCache
attribute without filtering/varying, because that would mean that the page would be cached once. I want the page to be cached once for every possible status code.
Is it possible to somehow filter/vary with OutputCacheAttribute
's properties, so that each Response.StatusCode is cached separately?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您当前如何处理到错误操作的路由,例如您可以:
所有都指向完全相同的操作,并且将为您处理缓存,因为它们是独立的 url,并且您将 OutputCache 属性一次应用于通用错误操作:
这可行吗?
How are you currently handling the routing to your error action, e.g. you could have:
All pointing to the exact same action, and the caching will be handled for you because they are independent urls and you apply the OutputCache attribute a single time to the generic error action:
Would that work?