HttpResponseExtensions Class
Response-shaping helpers shared by the MVC and Minimal API adapters.
public static class HttpResponseExtensionsInheritance System.Object → HttpResponseExtensions
Methods
HttpResponseExtensions.SetCacheableHeaders(this HttpResponse, TimeSpan) Method
Advertises a positive cache lifetime for a public, cacheable metadata response - the JWKS endpoint. Sets
Cache-Control: public, max-age=<maxAge> and clears any Pragma / Expires a
no-cache policy left behind, so the response carries a single, non-contradictory caching directive. Size
maxAge to the key-rollover propagation window, so a client honouring the header always
holds a new signing key's public half before the server produces tokens with it.
public static void SetCacheableHeaders(this Microsoft.AspNetCore.Http.HttpResponse response, System.TimeSpan maxAge);Parameters
response Microsoft.AspNetCore.Http.HttpResponse
The HTTP response to modify.
maxAge System.TimeSpan
How long a shared or private cache may reuse the response.
HttpResponseExtensions.SetNoCacheHeaders(this HttpResponse) Method
Sets comprehensive no-cache headers on the response to prevent caching. Ensures responses containing sensitive information (tokens, credentials, logout pages) are never cached.
public static void SetNoCacheHeaders(this Microsoft.AspNetCore.Http.HttpResponse response);Parameters
response Microsoft.AspNetCore.Http.HttpResponse
The HTTP response to modify.
Remarks
Sets the following headers for maximum compatibility:
- Cache-Control: "no-store, no-cache, max-age=0, s-maxage=0" - Prevents storage in any cache (HTTP/1.1)
- Pragma: "no-cache" - Prevents caching in HTTP/1.0 proxies and legacy browsers
- Expires: Unix epoch - Sets expiration to the past for HTTP/1.0 compatibility