2

我花了一整天的时间来解决问题,但我无法解决:问题是:在操作上我有输出缓存属性:

[OutputCache(Duration = 600, VaryByParam = "*", VaryByCustom = "User")]

我也像这样重写了 Global.asax:

public override string GetVaryByCustomString(HttpContext context, string arg)
{
    if (arg == "User")
    {
        return "User=" + context.User.Identity.Name;
    }

    return base.GetVaryByCustomString(context, arg);
}

但是当我第一次登录时它会缓存这些值,然后当我尝试注销并再次以其他用户身份登录时,我会看到以前的缓存值。在调试时,我检查了 Identity.Name 是否为第一个用户返回正确的结果,它是“admin”,第二个用户是“kate”

4

1 回答 1

12

我找到了答案。我不得不说:Location = OutputCacheLocation.Server,在另一种情况下它缓存在客户端这是错误的。

所以 outputcache 属性应该是这样的:

[OutputCache(Duration = 600, VaryByParam = "*", VaryByCustom = "User", Location = OutputCacheLocation.Server)]
public ActionResult Index(<my parameters>)
于 2013-09-03T09:37:42.277 回答