[英]How can I override [ResponseCache] attribute property later in the action method?
I have a [ResponseCache] attribute on an action method with the default cache Location = ResponseCacheLocation.Any.我在默认缓存位置 = ResponseCacheLocation.Any 的操作方法上有一个 [ResponseCache] 属性。 But in few cases only I want to override this property to ResponseCacheLocation.Client.
但在少数情况下,我只想将此属性覆盖到 ResponseCacheLocation.Client。
Is there a better way to override the attribute in the action method code than using Response.Headers.Add?有没有比使用 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.在单元测试中使用 DefaultHttpContext 我可以访问 GetTypedHeaders,但我无法从 controller 中的真实响应中访问此方法。
I can confirm that the [ResponseCache]
attribute can be overridden within the action method in the following way:我可以通过以下方式确认可以在操作方法中覆盖
[ResponseCache]
属性:
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".但是,我认为没有更好的方法来处理这种“规则例外”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.