我想在我的 asp.net 页面上使用页面级缓存。随参数变化工作正常 - 但是,页面内容以原始请求的语言缓存。如果请求相同的 url/参数,并且用户在与第一个请求不同的区域设置(例如法语而不是英语)中查看 - 缓存会以原始请求的语言(英语)返回页面内容。有没有办法根据参数变化和基页面类中的值(例如从 Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName 返回的属性值)来缓存页面?
最佳答案
在 OutputCache 中设置 VaryByCustom="Language"
并更新 Global.asax 文件以通过添加以下代码来覆盖 HttpApplication.GetVaryByCustomString 方法:
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (custom.Equals("Language"))
{
return System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
}
else
{
return base.GetVaryByCustomString(context, custom);
}
}
此代码将使缓存依赖的参数是您的页面文化。
关于asp.net - 是否可以使用 asp.net 页面级缓存,并根据参数和本地化进行变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6821324/