3

I have a [ResponseCache] attribute on an action method with the default cache Location = ResponseCacheLocation.Any. But in few cases only I want to override this property to ResponseCacheLocation.Client.

Is there a better way to override the attribute in the action method code than using Response.Headers.Add ? (not even sure if it would work)

Using DefaultHttpContext in the unit test I can access to GetTypedHeaders, but I don't have access to this method from the real Response in the controller.

Jonathan
  • 1,276
  • 10
  • 35

1 Answers1

2

I can confirm that the [ResponseCache] attribute can be overridden within the action method in the following way:

HttpContext.Response.Headers["Cache-Control"] = "private,no-cache, no-store, max-age=0";

However, I don't think there's a better way to handle these kind of "exceptions to the rule".

Darkseal
  • 9,205
  • 8
  • 78
  • 111