Вопрос

I spend whole day to figure out the problem but I couldn't: Here is the problem: On the action I have output cache attribute:

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

Also I've rewritten the Global.asax like this:

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

    return base.GetVaryByCustomString(context, arg);
}

But when I login first time it caches the values, then when I try to logout and again login as different user I see the previous cached value. While debugging I checked that Identity.Name returns correct results for the first user it is "admin" for the second user it is "kate"

Это было полезно?

Решение

I have found the answer. I had to put: Location = OutputCacheLocation.Server, in another case it caches on the client side which is wrong.

So the outputcache attribute should look like this:

[OutputCache(Duration = 600, VaryByParam = "*", VaryByCustom = "User", Location = OutputCacheLocation.Server)]
public ActionResult Index(<my parameters>)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top