2017-11-10 14 views
0

에서 누락 된 Vary 헤더!MVC asp.net OutputCache를 내가 <code>Response.Cache.SetCacheability(HttpCacheability.Private)</code> 및 <code>Response.Cache.VaryByHeaders["someValue"] = true;</code> <code>Vary</code> 헤더가 응답에서</strong> 누락 <strong>인을 사용하면 응답

Response.Cache.SetCacheability(HttpCacheability.Public)Response.Cache.VaryByHeaders["someValue"] = true;에도 불구하고 NO 문제가 있습니다. Web.config의 컨트롤러를 사용하는 경우 someValue와

같은 문제

이 활성화 = "true"를 기간 = "3600"VaryByParam 특성 = "*"varyByHeader = "someValue와를"이름 = "myCacheProfile"를 추가 속성 : 그것은 반환 비바리 위치 = "하류는"작품과는 = "true"를 기간 = "3600"VaryByParam 특성 = "*"varyByHeader = "someValue와"위치 = "클라이언트"나던 작업 가능 이름 = "myCacheProfile"를 추가 헤더를

비바리 보냅니다! 당신 싶어 사용하는 사용자 정의 값, 당신은 Global.asax.cs 파일에 재정의를 수행해야하는 경우

답변

0

:

public override string GetVaryByCustomString(HttpContext context, string custom) 
     { 
      if (!string.IsNullOrEmpty(custom) && context != null && context.Request != null) 
      {     
       HttpRequest req = context.Request; 

       switch (custom.ToUpper()) 
       { 
        case "someValue": 
         return req.someValue; 
        case "USER-AGENT": 
         if (req.UserAgent != null && req.Browser != null) 
          return req.UserAgent.ToString() + "-" + req.Browser.IsMobileDevice.ToString() + "-" + req.Browser.Platform; 
         else 
          return base.GetVaryByCustomString(context, custom); 
        default: 
         return base.GetVaryByCustomString(context, custom); 
       } 
      } 
      return base.GetVaryByCustomString(context, custom); 
     } 
+0

가 없음이는 VaryByCustom되지는 VaryByHeaders입니다 –