ASP.NET的OutputCache的VaryByParam和VaryByHeader与AJAX [英] ASP.NET OutPutCache VaryByParam and VaryByHeader with AJAX

查看:146
本文介绍了ASP.NET的OutputCache的VaryByParam和VaryByHeader与AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做使用的VaryByParam和VaryByHeader一些缓存。当一个AJAX请求到来时我返回部分XHTML。当一个普通请求进入我页眉/页脚发送局部XHTML页面。

I'm trying to do some caching using VaryByParam AND VaryByHeader. When an AJAX request comes in I return a partial XHTML. When a regular request comes in I send the partial XHTML page with header / footer.

我试图做缓存的页面:

[OutputCache( Duration = 5, VaryByParam = "nickname,page", VaryByHeader = "X-Requested-With" )]

然而,这不工作...如果我首先做一个普通的请求然后运行AJAX调用我得到充分的缓存页面,而不是局部的,反之亦然。好像被忽略VaryByHeader。是不是因为的X请求 - 由于省略了正常的请求?也许它做的VaryByParam或VaryByHeader?

However this doesn't work... if I do a regular request first then run the AJAX call I get the full cached page instead of the partial and vice-versa. Seems like VaryByHeader is being ignored. Is it because X-Requested-With is omitted on normal requests? Or perhaps it's doing VaryByParam OR VaryByHeader?

解决这个我明显的方法是AJAX请求调用不同的方法,该方法只返回部分页面,但我想避免,如果可能的。

My obvious way around this is for AJAX requests to call a different method which only returns partial pages, however I'd like to avoid that if possible.

我使用ASP.NET MVC 1.0在 OutputCacheAttribute

I'm using ASP.NET MVC 1.0 with the OutputCacheAttribute.

推荐答案

据的这个MSDN参考中的VaryByParam多个值应分号隔开,而不是逗号分隔。

According to this MSDN reference, multiple values in VaryByParam should be semicolon separated, not comma separated.

这篇关于ASP.NET的OutputCache的VaryByParam和VaryByHeader与AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆