Reputation: 4934
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.
Upvotes: 15
Views: 6778
Reputation: 12395
Expires is a content header. Try this instead:
actionExecutedContext.Response.Content.Headers.Expires = DateTimeOffset.Now.AddDays(7);
Upvotes: 27
Reputation: 6793
Try
response.Content.Headers.Expires = DateTimeOffset.Now.AddDays(7);
Upvotes: 1