Ser*_*gey 2 c# asp.net-mvc caching outputcache
我花了一整天来弄清楚问题,但我不能:这是问题:在操作上我有输出缓存属性:
[OutputCache(Duration = 600, VaryByParam = "*", VaryByCustom = "User")]
Run Code Online (Sandbox Code Playgroud)
我也像这样重写了Global.asax:
public override string GetVaryByCustomString(HttpContext context, string arg)
{
if (arg == "User")
{
return "User=" + context.User.Identity.Name;
}
return base.GetVaryByCustomString(context, arg);
}
Run Code Online (Sandbox Code Playgroud)
但是当我第一次登录时它会缓存值,然后当我尝试注销并再次以不同的用户身份登录时,我会看到之前的缓存值.在调试时,我检查了Identity.Name为第一个用户返回正确的结果,对于第二个用户,它是"admin",它是"kate"
Ser*_*gey 12
我找到了答案.我不得不把:Location = OutputCacheLocation.Server,在另一种情况下,它在客户端缓存是错误的.
所以outputcache属性应如下所示:
[OutputCache(Duration = 600, VaryByParam = "*", VaryByCustom = "User", Location = OutputCacheLocation.Server)]
public ActionResult Index(<my parameters>)
Run Code Online (Sandbox Code Playgroud)