출력 캐시는 ASP.NET MVC2에서 아래 코드를 사용하여 구현됩니다.GetVaryByCustomString이 호출되지 않는 이유
GetVaryByCustomString
메서드가 호출되지 않습니다. 첫 번째 줄에 중단 점을 배치하고 응용 프로그램을 실행하면 중단 점에 도달하지 않은 것으로 나타납니다. 컨트롤러 인덱스()의 중단 점에 도달했습니다.
VaryByCustom
을 ASP.NET MVC2에서 사용하는 방법은 무엇입니까?
컨트롤러 :
[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);
}
}
감사합니다. 이 Vary : * 헤더를 추가하면 브라우저에 * 헤더가 전송되고 브라우저 캐시가 비활성화됩니다. VaryByCustom으로 브라우저 캐시를 사용하는 방법은 무엇입니까? – Andrus