UseAuthorization and UseAuthentication order in 3.0 migration. (#12914)
parent
19b31e3aa7
commit
79aac148ca
|
@ -4,7 +4,7 @@ author: tdykstra
|
|||
description: Learn how to migrate an ASP.NET Core 2.2 project to ASP.NET Core 3.0.
|
||||
ms.author: tdykstra
|
||||
ms.custom: mvc
|
||||
ms.date: 05/10/2019
|
||||
ms.date: 06/17/2019
|
||||
uid: migration/22-to-30
|
||||
---
|
||||
# Migrate from ASP.NET Core 2.2 to 3.0
|
||||
|
@ -187,11 +187,11 @@ public void Configure(IApplicationBuilder app)
|
|||
|
||||
### Security middleware guidance
|
||||
|
||||
Support for authorization and CORS is unified around the [middleware](xref:fundamentals/middleware/index) approach. This allows use of the same middleware and functionality across these scenarios. An updated authorization middleware is provided in this release, and CORS middleware is enhanced so that it can understand the attributes used by MVC controllers.
|
||||
Support for authorization and CORS is unified around the [middleware](xref:fundamentals/middleware/index) approach. This allows use of the same middleware and functionality across these scenarios. An updated authorization middleware is provided in this release, and CORS Middleware is enhanced so that it can understand the attributes used by MVC controllers.
|
||||
|
||||
#### CORS
|
||||
|
||||
Previously, CORS could be difficult to configure. Middleware was provided for use in some use cases, but MVC filters were intended to be used **without** the middleware in other use cases. With ASP.NET Core 3.0, we recommend that all apps that require CORS use the CORS middleware in tandem with Endpoint Routing. `UseCors` can be provided with a default policy, and `[EnableCors]` and `[DisableCors]` attributes can be used to override the default policy where required.
|
||||
Previously, CORS could be difficult to configure. Middleware was provided for use in some use cases, but MVC filters were intended to be used **without** the middleware in other use cases. With ASP.NET Core 3.0, we recommend that all apps that require CORS use the CORS Middleware in tandem with Endpoint Routing. `UseCors` can be provided with a default policy, and `[EnableCors]` and `[DisableCors]` attributes can be used to override the default policy where required.
|
||||
|
||||
In the following example:
|
||||
|
||||
|
@ -222,7 +222,7 @@ public class MyController : ControllerBase
|
|||
|
||||
#### Authorization
|
||||
|
||||
In earlier versions of ASP.NET Core, authorization support was provided via the `[Authorize]` attribute. Authorization middleware wasn't available. In ASP.NET Core 3.0, authorization middleware is required. We recommend placing the authorization middleware (`UseAuthentication`) immediately before `UseAuthorization`. Authorization middleware can also be configured with a default policy, which can be overridden.
|
||||
In earlier versions of ASP.NET Core, authorization support was provided via the `[Authorize]` attribute. Authorization middleware wasn't available. In ASP.NET Core 3.0, authorization middleware is required. We recommend placing the ASP.NET Core Authorization Middleware (`UseAuthorization`) immediately after `UseAuthentication`. The Authorization Middleware can also be configured with a default policy, which can be overridden.
|
||||
|
||||
In ASP.NET Core 3.0 or later, `UseAuthorization` is called in `Startup.Configure`, and the following `HomeController` requires a signed in user:
|
||||
|
||||
|
@ -389,7 +389,7 @@ public void Configure(IApplicationBuilder app)
|
|||
|
||||
### Use MVC without Endpoint Routing
|
||||
|
||||
Using MVC via `UseMvc` or `UseMvcWithDefaultRoute` in ASP.NET Core 3.0 requires an explicit opt-in inside `Startup.ConfigureServices`. This is required because MVC must know whether it can rely on the authorization and CORS middleware during initialization. An analyzer is provided that warns if the app attempts to use an unsupported configuration.
|
||||
Using MVC via `UseMvc` or `UseMvcWithDefaultRoute` in ASP.NET Core 3.0 requires an explicit opt-in inside `Startup.ConfigureServices`. This is required because MVC must know whether it can rely on the authorization and CORS Middleware during initialization. An analyzer is provided that warns if the app attempts to use an unsupported configuration.
|
||||
|
||||
If the app requires legacy `IRouter` support, disable `EnableEndpointRouting` using any of the following approaches in `Startup.ConfigureServices`:
|
||||
|
||||
|
|
Loading…
Reference in New Issue