当我在其中放置断点时,不会触发 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);
}
任何帮助将不胜感激,谢谢!