سؤال

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