How to add an Expires response header to a WebAPI Action response?
asp.net-web-api, caching, http-headers
Solution
Expires is a content header. Try this instead:
actionExecutedContext.Response.Content.Headers.Expires = DateTimeOffset.Now.AddDays(7);
Problem
I'm pretty sure that "Expires" is valid HTTP Response Header type. But when I try to set it in my code: (this is in an ActionFilter.OnActionExecuted method) ``` actionExecutedContext.Response.Headers.Add("Expires", (DateTime.Now + Timespan.FromDays(7)).ToString("R")); ``` I end up with an exception: InvalidOperationException: Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.