【发布时间】:2015-01-31 09:06:47
【问题描述】:
当我在 GetVaryByCustomString 方法中放置断点时,它不会被触发。
我要缓存的操作取决于用户选择的语言:
[OutputCache(CacheProfile = "24HoursCache", VaryByCustom = "lang")]
public ActionResult MyAction()
{
...
}
Web.config 中的缓存配置文件:
<configuration>
...
<system.web>
...
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<clear />
<add name="24HoursCache" duration="86400" location="Client" varyByParam="none" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
</system.web>
...
</configuration>
在 Global.asax.cs 文件中:
public override string GetVaryByCustomString(HttpContext context, string value)
{
if (value.ToLower() == "lang")
{
return Thread.CurrentThread.CurrentUICulture.Name;
}
return base.GetVaryByCustomString(context, value);
}
任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: c# asp.net-mvc outputcache varybyparam