The output cache is implemented in ASP.NET MVC2 using the code below.
GetVaryByCustomString method is not called: placing a breakpoint on the first line and the running application shows that the breakpoint has not been reached. A breakpoint has been reached in the Index () controller.
How to use VaryByCustom in ASP.NET MVC2?
Controller:
[OutputCache(VaryByCustom = "user")] public ActionResult Index(string _entity, string id) { ...
Global.asax.cs:
public class MvcApplication : System.Web.HttpApplication { public override string GetVaryByCustomString(HttpContext context, string arg) { if (arg == "user") { HttpCookie cookie = context.Request.Cookies["Company"]; if (cookie != null) return Thread.CurrentPrincipal.Identity.Name + "," + cookie.Value; return Thread.CurrentPrincipal.Identity.Name; } return base.GetVaryByCustomString(context, arg); } }
Andrus
source share