You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/middleware/index.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,9 @@ The following `Startup.Configure` method adds security-related middleware compon
80
80
In the preceding code:
81
81
82
82
* Middleware that is not added when creating a new web app with [individual users accounts](xref:security/authentication/identity) is commented out.
83
-
* Not every middleware needs to go in this exact order, but many do. For example, `UseCors`, `UseAuthentication`, and `UseAuthorization` must go in the order shown.
83
+
* Not every middleware needs to go in this exact order, but many do. For example:
84
+
*`UseCors`, `UseAuthentication`, and `UseAuthorization` must go in the order shown.
85
+
*`UseCors` currently must go before `UseResponseCaching` due to [this bug](https://github.com/dotnet/aspnetcore/issues/23218).
84
86
85
87
The following `Startup.Configure` method adds middleware components for common app scenarios:
86
88
@@ -237,7 +239,7 @@ ASP.NET Core ships with the following middleware components. The *Order* column
237
239
|[Authentication](xref:security/authentication/identity)| Provides authentication support. | Before `HttpContext.User` is needed. Terminal for OAuth callbacks. |
238
240
|[Authorization](xref:Microsoft.AspNetCore.Builder.AuthorizationAppBuilderExtensions.UseAuthorization*)| Provides authorization support. | Immediately after the Authentication Middleware. |
239
241
|[Cookie Policy](xref:security/gdpr)| Tracks consent from users for storing personal information and enforces minimum standards for cookie fields, such as `secure` and `SameSite`. | Before middleware that issues cookies. Examples: Authentication, Session, MVC (TempData). |
240
-
|[CORS](xref:security/cors)| Configures Cross-Origin Resource Sharing. | Before components that use CORS. |
242
+
|[CORS](xref:security/cors)| Configures Cross-Origin Resource Sharing. | Before components that use CORS. `UseCors` currently must go before `UseResponseCaching` due to [this bug](https://github.com/dotnet/aspnetcore/issues/23218).|
241
243
|[Diagnostics](xref:fundamentals/error-handling)| Several separate middlewares that provide a developer exception page, exception handling, status code pages, and the default web page for new apps. | Before components that generate errors. Terminal for exceptions or serving the default web page for new apps. |
242
244
|[Forwarded Headers](xref:host-and-deploy/proxy-load-balancer)| Forwards proxied headers onto the current request. | Before components that consume the updated fields. Examples: scheme, host, client IP, method. |
243
245
|[Health Check](xref:host-and-deploy/health-checks)| Checks the health of an ASP.NET Core app and its dependencies, such as checking database availability. | Terminal if a request matches a health check endpoint. |
@@ -247,7 +249,7 @@ ASP.NET Core ships with the following middleware components. The *Order* column
247
249
|[HTTP Strict Transport Security (HSTS)](xref:security/enforcing-ssl#http-strict-transport-security-protocol-hsts)| Security enhancement middleware that adds a special response header. | Before responses are sent and after components that modify requests. Examples: Forwarded Headers, URL Rewriting. |
248
250
|[MVC](xref:mvc/overview)| Processes requests with MVC/Razor Pages. | Terminal if a request matches a route. |
249
251
|[OWIN](xref:fundamentals/owin)| Interop with OWIN-based apps, servers, and middleware. | Terminal if the OWIN Middleware fully processes the request. |
250
-
|[Response Caching](xref:performance/caching/middleware)| Provides support for caching responses. | Before components that require caching. |
252
+
|[Response Caching](xref:performance/caching/middleware)| Provides support for caching responses. | Before components that require caching. `UseCORS` must come before `UseResponseCaching`.|
251
253
|[Response Compression](xref:performance/response-compression)| Provides support for compressing responses. | Before components that require compression. |
Copy file name to clipboardExpand all lines: aspnetcore/performance/caching/middleware.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,10 @@ In `Startup.ConfigureServices`, add the Response Caching Middleware to the servi
29
29
30
30
Configure the app to use the middleware with the <xref:Microsoft.AspNetCore.Builder.ResponseCachingExtensions.UseResponseCaching*> extension method, which adds the middleware to the request processing pipeline in `Startup.Configure`:
> <xref:Owin.CorsExtensions.UseCors%2A> must be called before <xref:Microsoft.AspNetCore.Builder.ResponseCachingExtensions.UseResponseCaching%2A> when using [CORS middleware](xref:security/cors).
33
36
34
37
The sample app adds headers to control caching on subsequent requests:
Copy file name to clipboardExpand all lines: aspnetcore/security/cors.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,9 @@ There are three ways to enable CORS:
53
53
54
54
Using the [[EnableCors]](#attr) attribute with a named policy provides the finest control in limiting endpoints that support CORS.
55
55
56
+
> [!WARNING]
57
+
> <xref:Owin.CorsExtensions.UseCors%2A> must be called before <xref:Microsoft.AspNetCore.Builder.ResponseCachingExtensions.UseResponseCaching%2A> when using `UseResponseCaching`.
58
+
56
59
Each approach is detailed in the following sections.
57
60
58
61
<aname="np"></a>
@@ -61,14 +64,15 @@ Each approach is detailed in the following sections.
61
64
62
65
CORS Middleware handles cross-origin requests. The following code applies a CORS policy to all the app's endpoints with the specified origins:
* Sets the policy name to `_myAllowSpecificOrigins`. The policy name is arbitrary.
69
72
* Calls the <xref:Microsoft.AspNetCore.Builder.CorsMiddlewareExtensions.UseCors*> extension method and specifies the `_myAllowSpecificOrigins` CORS policy. `UseCors` adds the CORS middleware. The call to `UseCors` must be placed after `UseRouting`, but before `UseAuthorization`. For more information, see [Middleware order](xref:fundamentals/middleware/index#middleware-order).
70
73
* Calls <xref:Microsoft.Extensions.DependencyInjection.CorsServiceCollectionExtensions.AddCors*> with a [lambda expression](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions). The lambda takes a <xref:Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder> object. [Configuration options](#cors-policy-options), such as `WithOrigins`, are described later in this article.
71
74
* Enables the `_myAllowSpecificOrigins` CORS policy for all controller endpoints. See [endpoint routing](#ecors) to apply a CORS policy to specific endpoints.
75
+
* When using [Response Caching Middleware](xref:performance/caching/middleware), call <xref:Owin.CorsExtensions.UseCors%2A> before <xref:Microsoft.AspNetCore.Builder.ResponseCachingExtensions.UseResponseCaching%2A>.
72
76
73
77
With endpoint routing, the CORS middleware **must** be configured to execute between the calls to `UseRouting` and `UseEndpoints`.
0 commit comments