我读过一些不同的东西,听起来输出缓存不会为每个用户缓存不同的结果副本。因此,如果用户 A 有 3 个菜单而用户 B 只能访问其中的 1 个,那么缓存 View 结果将显示所有 3 个?

我如何为每个用户缓存内容,使其不被共享?

谢谢!

最佳答案

使用 VaryByCustom 并重新定义 HttpApplication.GetVaryByCustomString:

public virtual string GetVaryByCustomString(
    HttpContext context,
    string custom
)
{
    //Return a value unique per user
    //Change depending on the authentication of your site (f.e. make use of Session)
    return context.User.Identity.Name;
}

http://msdn.microsoft.com/en-us/library/system.web.httpapplication.getvarybycustomstring.aspx
http://asp.net-tutorials.com/caching/more-output-cache/

关于asp.net-mvc - asp.net mvc 输出缓存,我可以缓存不同用户的不同结果吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3425006/

10-11 21:59
查看更多