1

When I use Response.Cache.SetCacheability(HttpCacheability.Private) and Response.Cache.VaryByHeaders["someValue"] = true; the Vary header is missing from the response!

There is NO problem with the Response.Cache.SetCacheability(HttpCacheability.Public) and Response.Cache.VaryByHeaders["someValue"] = true; although. It Returns Vary: someValue

The same problem when using web.config and controller attributes

add name="myCacheProfile" enabled="true" duration="3600" varyByParam="*" varyByHeader="someValue" location="Downstream" Works and sends the Vary header

add name="myCacheProfile" enabled="true" duration="3600" varyByParam="*" varyByHeader="someValue" location="Client" doesnt work!

J.P.
  • 21
  • 5

1 Answers1

0

If you wanna use custom values, you must do an override in the Global.asax.cs file:

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);
        }
Axel Andersen
  • 330
  • 4
  • 14