---
title: Migrate from ASP.NET Core 2.2 to 3.0
author: rick-anderson
description: Learn how to migrate an ASP.NET Core 2.2 project to ASP.NET Core 3.0.
ms.author: riande
ms.custom: mvc
ms.date: 09/16/2019
uid: migration/22-to-30
---
# Migrate from ASP.NET Core 2.2 to 3.0
By [Scott Addie](https://github.com/scottaddie) and [Rick Anderson](https://twitter.com/RickAndMSFT)
This article explains how to update an existing ASP.NET Core 2.2 project to ASP.NET Core 3.0.
## Prerequisites
# [Visual Studio](#tab/visual-studio)
[!INCLUDE[](~/includes/net-core-prereqs-vs-3.0.md)]
# [Visual Studio Code](#tab/visual-studio-code)
[!INCLUDE[](~/includes/net-core-prereqs-vsc-3.0.md)]
# [Visual Studio for Mac](#tab/visual-studio-mac)
[!INCLUDE[](~/includes/net-core-prereqs-mac-3.0.md)]
---
## Update the project file
### Update the Target Framework
ASP.NET Core 3.0 and later will only run on .NET Core. Set the [Target Framework Moniker (TFM)](/dotnet/standard/frameworks) to `netcoreapp3.0`:
```xml
netcoreapp3.0
```
### Remove obsolete package references
ASP.NET Core no longer produces a large number of NuGet packages features. These package references should be removed from your project file. To see the full list of packages that are no longer produced, see below:
Click here to expand the list of packages no longer being produced
* Microsoft.AspNetCore
* Microsoft.AspNetCore.All
* Microsoft.AspNetCore.App
* Microsoft.AspNetCore.Antiforgery
* Microsoft.AspNetCore.Authentication
* Microsoft.AspNetCore.Authentication.Abstractions
* Microsoft.AspNetCore.Authentication.Cookies
* Microsoft.AspNetCore.Authentication.Core
* Microsoft.AspNetCore.Authentication.JwtBearer
* Microsoft.AspNetCore.Authentication.OAuth
* Microsoft.AspNetCore.Authentication.OpenIdConnect
* Microsoft.AspNetCore.Authorization
* Microsoft.AspNetCore.Authorization.Policy
* Microsoft.AspNetCore.CookiePolicy
* Microsoft.AspNetCore.Cors
* Microsoft.AspNetCore.Cryptography.Internal
* Microsoft.AspNetCore.Cryptography.KeyDerivation
* Microsoft.AspNetCore.DataProtection
* Microsoft.AspNetCore.DataProtection.Abstractions
* Microsoft.AspNetCore.DataProtection.Extensions
* Microsoft.AspNetCore.Diagnostics
* Microsoft.AspNetCore.Diagnostics.HealthChecks
* Microsoft.AspNetCore.HostFiltering
* Microsoft.AspNetCore.Hosting
* Microsoft.AspNetCore.Hosting.Abstractions
* Microsoft.AspNetCore.Hosting.Server.Abstractions
* Microsoft.AspNetCore.Http
* Microsoft.AspNetCore.Http.Abstractions
* Microsoft.AspNetCore.Http.Connections
* Microsoft.AspNetCore.Http.Extensions
* Microsoft.AspNetCore.Http.Features
* Microsoft.AspNetCore.HttpOverrides
* Microsoft.AspNetCore.HttpsPolicy
* Microsoft.AspNetCore.Identity
* Microsoft.AspNetCore.Localization
* Microsoft.AspNetCore.Localization.Routing
* Microsoft.AspNetCore.MiddlewareAnalysis
* Microsoft.AspNetCore.Mvc
* Microsoft.AspNetCore.Mvc.Abstractions
* Microsoft.AspNetCore.Mvc.Analyzers
* Microsoft.AspNetCore.Mvc.ApiExplorer
* Microsoft.AspNetCore.Mvc.Api.Analyzers
* Microsoft.AspNetCore.Mvc.Core
* Microsoft.AspNetCore.Mvc.Cors
* Microsoft.AspNetCore.Mvc.DataAnnotations
* Microsoft.AspNetCore.Mvc.Formatters.Json
* Microsoft.AspNetCore.Mvc.Formatters.Xml
* Microsoft.AspNetCore.Mvc.Localization
* Microsoft.AspNetCore.Mvc.Razor
* Microsoft.AspNetCore.Mvc.Razor.Extensions
* Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
* Microsoft.AspNetCore.Mvc.RazorPages
* Microsoft.AspNetCore.Mvc.TagHelpers
* Microsoft.AspNetCore.Mvc.ViewFeatures
* Microsoft.AspNetCore.Razor
* Microsoft.AspNetCore.Razor.Runtime
* Microsoft.AspNetCore.Razor.Design
* Microsoft.AspNetCore.ResponseCaching
* Microsoft.AspNetCore.ResponseCaching.Abstractions
* Microsoft.AspNetCore.ResponseCompression
* Microsoft.AspNetCore.Rewrite
* Microsoft.AspNetCore.Routing
* Microsoft.AspNetCore.Routing.Abstractions
* Microsoft.AspNetCore.Server.HttpSys
* Microsoft.AspNetCore.Server.IIS
* Microsoft.AspNetCore.Server.IISIntegration
* Microsoft.AspNetCore.Server.Kestrel
* Microsoft.AspNetCore.Server.Kestrel.Core
* Microsoft.AspNetCore.Server.Kestrel.Https
* Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions
* Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
* Microsoft.AspNetCore.Session
* Microsoft.AspNetCore.SignalR
* Microsoft.AspNetCore.SignalR.Core
* Microsoft.AspNetCore.StaticFiles
* Microsoft.AspNetCore.WebSockets
* Microsoft.AspNetCore.WebUtilities
* Microsoft.Net.Http.Headers
### Framework reference
Features of ASP.NET Core that were available through one of the packages listed above are available as part of the `Microsoft.AspNetCore.App` shared framework. The *shared framework* is the set of assemblies (*.dll* files) that are installed on the machine and includes a runtime component, and a targeting pack. For more information, see [The shared framework](https://natemcmaster.com/blog/2018/08/29/netcore-primitives-2/).
* Projects that target the `Microsoft.NET.Sdk.Web` SDK implicitly reference the `Microsoft.AspNetCore.App` framework.
No additional references are required for these projects:
```xml
netcoreapp3.0
...
```
* Projects that target `Microsoft.NET.Sdk` or `Microsoft.NET.Sdk.Razor` SDK, should add an explicit `FrameworkReference` to `Microsoft.AspNetCore.App`:
```xml
netcoreapp3.0
...
```
### Add package references for removed assemblies
ASP.NET Core 3.0 removes some assemblies that were previously part of the `Microsoft.AspNetCore.App` package reference. To continue using features provided by these assemblies, reference the 3.0 versions of the corresponding packages:
* Entity Framework Core - See https://docs.microsoft.com/ef/core/providers/index for more information on referencing the database provider-specific package.
* Identity UI
Support for [Identity UI](xref:security/authentication/identity) can be added by referencing the [Microsoft.AspNetCore.Identity.UI](https://www.nuget.org/packages/Microsoft.AspNetCore.Identity.UI) package.
* SPA Services
* [Microsoft.AspNetCore.SpaServices](https://www.nuget.org/packages/Microsoft.AspNetCore.SpaServices)
* [Microsoft.AspNetCore.SpaServices.Extensions](https://www.nuget.org/packages/Microsoft.AspNetCore.SpaServices.Extensions)
* Authentication - Support for third-party authentication flows are available as NuGet packages:
* [Facebook OAuth](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Facebook)
* [Google OAuth](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Google)
* [OpenID Connect bearer token](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.JwtBearer)
* [Microsoft Account authentication](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.MicrosoftAccount)
* [OpenID Connect authentication](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.OpenIdConnect)
* [Twitter OAuth](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Twitter)
* [WsFederation authentication](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.WsFederation)
* Formatting and content negotiation support for `System.Net.HttpClient` - The [Microsoft.AspNet.WebApi.Client](https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Client/) NuGet package provides useful extensibility to `System.Net.HttpClient` with APIs such as `ReadAsAsync`, `PostJsonAsync` etc.
* Razor runtime compilation - Support for runtime compilation of Razor views and pages is now part of [Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation).
* MVC `Newtonsoft.Json` support - Support for using MVC with `Newtonsoft.Json` is now part of [Microsoft.AspNetCore.Mvc.NewtonsoftJson](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.NewtonsoftJson).
### Analyzer support
* Projects that target `Microsoft.NET.Sdk.Web` implicitly reference analyzers previously shipped as part of the [Microsoft.AspNetCore.Mvc.Analyzers](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Analyzers/) package. No additional references are required to enable these.
* If your application uses [API analyzers](xref:web-api/advanced/analyzers) previously shipped using the [Microsoft.AspNetCore.Mvc.Api.Analyzers](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Api.Analyzers/) package, edit your project file to reference the analyzers shipped as part of the .NET Core Web SDK:
```xml
netcoreapp3.0
true
...
```
### Razor Class Library
Razor Class Library projects that provide UI components for MVC must set the `AddRazorSupportForMvc` property in the project file:
```xml
true
```
### In-process hosting model
* Projects default to the [in-process hosting model](xref:host-and-deploy/aspnet-core-module#in-process-hosting-model) in ASP.NET Core 3.0 or later. You may optionally remove the `` property in the project file if its value is `InProcess`.
## Kestrel
### Configuration
Migrate Kestrel configuration to the web host builder provided by `ConfigureWebHostDefaults` (*Program.cs*):
```csharp
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(serverOptions =>
{
// Set properties and call methods on options
})
.UseStartup();
});
```
If the app creates the host manually with `HostBuilder`, call `UseKestrel` on the web host builder in `ConfigureWebHostDefaults`:
```csharp
public static void Main(string[] args)
{
var host = new HostBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseKestrel(serverOptions =>
{
// Set properties and call methods on options
})
.UseIISIntegration()
.UseStartup();
})
.Build();
host.Run();
}
```
### Connection Middleware replaces Connection Adapters
Connection Adapters () have been removed from Kestrel. Replace Connection Adapters with Connection Middleware. Connection Middleware is similar to HTTP Middleware in the ASP.NET Core pipeline but for lower-level connections. HTTPS and connection logging:
* Have been moved from Connection Adapters to Connection Middleware.
* These extension methods work as in previous versions of ASP.NET Core.
For more information, see [the TlsFilterConnectionHandler example in the ListenOptions.Protocols section of the Kestrel article](/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.0#listenoptionsprotocols).
### Transport abstractions moved and made public
The Kestrel transport layer has been exposed as a public interface in `Connections.Abstractions`. As part of these updates:
* `Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions` and associated types have been removed.
* was moved from to the transport options.
* was removed from .
For more information, see the following GitHub resources:
* [Client/server networking abstractions (aspnet/AspNetCore #10308)](https://github.com/aspnet/AspNetCore/issues/10308)
* [Implement new bedrock listener abstraction and re-plat Kestrel on top (aspnet/AspNetCore #10321)](https://github.com/aspnet/AspNetCore/pull/10321)
### Kestrel Request trailer headers
For apps that target earlier versions of ASP.NET Core:
* Kestrel adds HTTP/1.1 chunked trailer headers into the request headers collection.
* Trailers are available after the request body is read to the end.
This causes some concerns about ambiguity between headers and trailers, so the trailers have been moved to a new collection (`RequestTrailerExtensions`) in 3.0.
HTTP/2 request trailers are:
* Not available in ASP.NET Core 2.2.
* Available in 3.0 as `RequestTrailerExtensions`.
New request extension methods are present to access these trailers. As with HTTP/1.1, trailers are available after the request body is read to the end.
For the 3.0 release, the following `RequestTrailerExtensions` methods are available:
* `GetDeclaredTrailers` – Gets the request `Trailer` header that lists which trailers to expect after the body.
* `SupportsTrailers` – Indicates if the request supports receiving trailer headers.
* `CheckTrailersAvailable` – Checks if the request supports trailers and if they're available to be read. This check doesn't assume that there are trailers to read. There might be no trailers to read even if `true` is returned by this method.
* `GetTrailer` – Gets the requested trailing header from the response. Check `SupportsTrailers` before calling `GetTrailer`, or a may occur if the request doesn't support trailing headers.
For more information, see [Put request trailers in a separate collection (aspnet/AspNetCore #10410)](https://github.com/aspnet/AspNetCore/pull/10410).
### AllowSynchronousIO disabled
`AllowSynchronousIO` enables or disables synchronous IO APIs, such as `HttpRequest.Body.Read`, `HttpResponse.Body.Write`, and `Stream.Flush`. These APIs are a source of thread starvation leading to app crashes. In 3.0, `AllowSynchronousIO` is disabled by default. For more information, see [the Synchronous IO section in the Kestrel article](/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.0#synchronous-io).
In addition to enabling `AllowSynchronousIO` with `ConfigureKestrel`'s options, synchronous IO can also be overridden on a per-request basis as a temporary mitigation:
```csharp
var syncIOFeature = HttpContext.Features.Get();
if (syncIOFeature != null)
{
syncIOFeature.AllowSynchronousIO = true;
}
```
If you have trouble with implementations or other streams that call synchronous APIs in [Dispose](/dotnet/standard/garbage-collection/implementing-dispose), call the new API instead.
For more information, see [[Announcement] AllowSynchronousIO disabled in all servers (aspnet/AspNetCore #7644)](https://github.com/aspnet/AspNetCore/issues/7644).
### Microsoft.AspNetCore.Server.Kestrel.Https assembly removed
In ASP.NET Core 2.1, the contents of *Microsoft.AspNetCore.Server.Kestrel.Https.dll* were moved to *Microsoft.AspNetCore.Server.Kestrel.Core.dll*. This was a non-breaking update using `TypeForwardedTo` attributes. For 3.0, the empty *Microsoft.AspNetCore.Server.Kestrel.Https.dll* assembly (and the NuGet package) have been removed.
Libraries referencing [Microsoft.AspNetCore.Server.Kestrel.Https](https://www.nuget.org/packages/Microsoft.AspNetCore.Server.Kestrel.Https) should update ASP.NET Core dependencies to 2.1 or later.
Apps and libraries targeting ASP.NET Core 2.1 or later should remove any direct references to the [Microsoft.AspNetCore.Server.Kestrel.Https](https://www.nuget.org/packages/Microsoft.AspNetCore.Server.Kestrel.Https) package.
## Json.NET support
As part of the work to [improve the ASP.NET Core shared framework](https://blogs.msdn.microsoft.com/webdev/2018/10/29/a-first-look-at-changes-coming-in-asp-net-core-3-0/), [Json.NET](https://www.newtonsoft.com/json/help/html/Introduction.htm) has been removed from the ASP.NET Core shared framework.
The default for ASP.NET Core is now [System.Text.Json](/dotnet/api/system.text.json?view=netcore-3.0), which is new in .NET Core 3.0. Consider using `System.Text.Json` when possible. It's high-performance and doesn't require an additional library dependency. However, since `System.Text.Json` is new, it might currently be missing features that your app needs.
Your app may require `Netwtonsoft.Json` integration if it uses `Newtonsoft.Json`-specific feature such as JsonPatch or converters or if it [formats](xref:web-api/advanced/formatting) `Newtonsoft.Json`-specific types.
To use Json.NET in an ASP.NET Core 3.0 SignalR project, see [Switch to Newtonsoft.Json](#switch-to-newtonsoftjson) in this document.
To use Json.NET in an ASP.NET Core 3.0 project:
* Add a package reference to [Microsoft.AspNetCore.Mvc.NewtonsoftJson](https://nuget.org/packages/Microsoft.AspNetCore.Mvc.NewtonsoftJson).
* Update `Startup.ConfigureServices` to call `AddNewtonsoftJson`.
```csharp
services.AddMvc()
.AddNewtonsoftJson();
```
`AddNewtonsoftJson` is compatible with the new MVC service registration methods:
* `AddRazorPages`
* `AddControllersWithViews`
* `AddControllers`
```csharp
services.AddControllers()
.AddNewtonsoftJson();
```
Json.NET settings can be set in the call to `AddNewtonsoftJson`:
```csharp
services.AddMvc()
.AddNewtonsoftJson(options =>
options.SerializerSettings.ContractResolver =
new CamelCasePropertyNamesContractResolver());
```
## MVC service registration
ASP.NET Core 3.0 adds new options for registering MVC scenarios inside `Startup.ConfigureServices`.
Three new top-level extension methods related to MVC scenarios on `IServiceCollection` are available. Templates use these new methods instead of `UseMvc`. However, `AddMvc` continues to behave as it has in previous releases.
The following example adds support for controllers and API-related features, but not views or pages. The API template uses this code:
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
}
```
The following example adds support for controllers, API-related features, and views, but not pages. The Web Application (MVC) template uses this code:
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}
```
The following example adds support for Razor Pages and minimal controller support. The Web Application template uses this code:
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
}
```
The new methods can also be combined. The following example is equivalent to calling `AddMvc` in ASP.NET Core 2.2:
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddRazorPages();
}
```
## Routing startup code
If an app calls `UseMvc` or `UseSignalR`, migrate the app to [Endpoint Routing](xref:fundamentals/routing) if possible. To improve Endpoint Routing compatibility with previous versions of MVC, we've reverted some of the changes in URL generation introduced in ASP.NET Core 2.2. If you experienced problems using Endpoint Routing in 2.2, expect improvements in ASP.NET Core 3.0 with the following exceptions:
* If the app implements `IRouter` or inherits from `Route`, use [DynamicRouteValuesTransformer](https://github.com/aspnet/AspNetCore.Docs/issues/12997) as the replacement.
* If the app directly accesses `RouteData.Routers` inside MVC to parse URLs, you can replace this with use of `LinkParser.ParsePathByEndpointName`.
* Define the route with a route name.
* Use `LinkParser.ParsePathByEndpointName` and pass in the desired route name.
Endpoint Routing supports the same route pattern syntax and route pattern authoring features as `IRouter`. Endpoint Routing supports `IRouteConstraint`. Endpoint routing supports `[Route]`, `[HttpGet]`, and the other MVC routing attributes.
For most applications, only `Startup` requires changes.
### Migrate Startup.Configure
General advice:
* Add `UseRouting`.
* If the app calls `UseStaticFiles`, place `UseStaticFiles` **before** `UseRouting`.
* If the app uses authentication/authorization features such as `AuthorizePage` or `[Authorize]`, place the call to `UseAuthentication` and `UseAuthorization` **after** `UseRouting` (and **after** `UseCors` if CORS Middleware is used).
* Replace `UseMvc` or `UseSignalR` with `UseEndpoints`.
* If the app uses [CORS](xref:security/cors) scenarios, such as `[EnableCors]`, place the call to `UseCors` before any other middleware that use CORS (for example, place `UseCors` before `UseAuthentication`, `UseAuthorization`, and `UseEndpoints`).
* Replace `IHostingEnvironment` with `IWebHostEnvironment` and add a `using` statement for the namespace.
* Replace `IApplicationLifetime` with ( namespace).
* Replace `EnvironmentName` with ( namespace).
The following code is an example of `Startup.Configure` in a typical ASP.NET Core 2.2 app:
```csharp
public void Configure(IApplicationBuilder app)
{
...
app.UseStaticFiles();
app.UseAuthentication();
app.UseSignalR(hubs =>
{
hubs.MapHub("/chat");
});
app.UseMvc(routes =>
{
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
}
```
After updating the previous `Startup.Configure` code:
```csharp
public void Configure(IApplicationBuilder app)
{
...
app.UseStaticFiles();
app.UseRouting();
app.UseCors();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub("/chat");
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
}
```
> [!WARNING]
> For most applications, calls to `UseAuthentication`, `UseAuthorization`, and `UseCors` must appear between the calls to `UseRouting` and `UseEndpoints` to be effective.
### Health Checks
Health Checks use endpoint routing with the Generic Host. In `Startup.Configure`, call `MapHealthChecks` on the endpoint builder with the endpoint URL or relative path:
```csharp
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/health");
});
```
Health Checks endpoints can:
* Specify one or more permitted hosts/ports.
* Require authorization.
* Require CORS.
For more information, see .
### 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.
#### 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.
In the following example:
* CORS is enabled for all endpoints with the `default` named policy.
* The `MyController` class disables CORS with the `[DisableCors]` attribute.
```csharp
public void Configure(IApplicationBuilder app)
{
...
app.UseRouting();
app.UseCors("default");
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});
}
[DisableCors]
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 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:
```csharp
public void Configure(IApplicationBuilder app)
{
...
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});
}
public class HomeController : ControllerBase
{
[Authorize]
public IActionResult BuyWidgets()
{
...
}
}
```
If the app uses an `AuthorizeFilter` as a global filter in MVC, we recommend refactoring the code to provide a policy in the call to `AddAuthorization`.
The `DefaultPolicy` is initially configured to require authentication, so no additional configuration is required. In the following example, MVC endpoints are marked as `RequireAuthorization` so that all requests must be authorized based on the `DefaultPolicy`. However, the `HomeController` allows access without the user signing into the app due to `[AllowAnonymous]`:
```csharp
public void Configure(IApplicationBuilder app)
{
...
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute().RequireAuthorization();
});
}
[AllowAnonymous]
public class HomeController : ControllerBase
{
...
}
```
Policies can also be customized. Building upon the previous example, the `DefaultPolicy` is configured to require authentication and a specific scope:
```csharp
public void ConfigureServices(IServiceCollection services)
{
...
services.AddAuthorization(options =>
{
options.DefaultPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.RequireScope("MyScope")
.Build();
});
}
public void Configure(IApplicationBuilder app)
{
...
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute().RequireAuthorization();
});
}
[AllowAnonymous]
public class HomeController : ControllerBase
{
...
}
```
Alternatively, all endpoints can be configured to require authorization without `[Authorize]` or `RequireAuthorization` by configuring a `FallbackPolicy`. The `FallbackPolicy` is different from the `DefaultPolicy`. The `DefaultPolicy` is triggered by `[Authorize]` or `RequireAuthorization`, while the `FallbackPolicy` is triggered when no other policy is set. `FallbackPolicy` is initially configured to allow requests without authorization.
The following example is the same as the preceding `DefaultPolicy` example but uses the `FallbackPolicy` to always require authentication on all endpoints except when `[AllowAnonymous]` is specified:
```csharp
public void ConfigureServices(IServiceCollection services)
{
...
services.AddAuthorization(options =>
{
options.FallbackPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.RequireScope("MyScope")
.Build();
});
}
public void Configure(IApplicationBuilder app)
{
...
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});
}
[AllowAnonymous]
public class HomeController : ControllerBase
{
...
}
```
Authorization by middleware works without the framework having any specific knowledge of authorization. For instance, [health checks](xref:host-and-deploy/health-checks) has no specific knowledge of authorization, but health checks can have a configurable authorization policy applied by the middleware.
Additionally, each endpoint can customize its authorization requirements. In the following example, `UseAuthorization` processes authorization with the `DefaultPolicy`, but the `/healthz` health check endpoint requires an `admin` user:
```csharp
public void Configure(IApplicationBuilder app)
{
...
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints
.MapHealthChecks("/healthz")
.RequireAuthorization(new AuthorizeAttribute(){ Roles = "admin", });
});
}
```
Protection is implemented for some scenarios. `UseEndpoint` middleware throws an exception if an authorization or CORS policy is skipped due to missing middleware. Analyzer support to provide additional feedback about misconfiguration is in progress.
### SignalR
Mapping of SignalR hubs now takes place inside `UseEndpoints`.
Map each hub with `MapHub`. As in previous versions, each hub is explicitly listed.
In the following example, support for the `ChatHub` SignalR hub is added:
```csharp
public void Configure(IApplicationBuilder app)
{
...
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub();
});
}
```
There is a new option for controlling message size limits from clients. For example, in `Startup.ConfigureServices`:
```csharp
services.AddSignalR(hubOptions =>
{
hubOptions.MaximumReceiveMessageSize = 32768;
});
```
In ASP.NET Core 2.2, you could set the `TransportMaxBufferSize` and that would effectively control the maximum message size. In ASP.NET Core 3.0, that option now only controls the maximum size before backpressure is observed.
### MVC controllers
Mapping of controllers now takes place inside `UseEndpoints`.
Add `MapControllers` if the app uses attribute routing. Since routing includes support for many frameworks in ASP.NET Core 3.0 or later, adding attribute-routed controllers is opt-in.
Replace the following:
* `MapRoute` with `MapControllerRoute`
* `MapAreaRoute` with `MapAreaControllerRoute`
Since routing now includes support for more than just MVC, the terminology has changed to make these methods clearly state what they do. Conventional routes such as `MapControllerRoute`/`MapAreaControllerRoute`/`MapDefaultControllerRoute` are applied in the order that they're added. Place more specific routes (such as routes for an area) first.
In the following example:
* `MapControllers` adds support for attribute-routed controllers.
* `MapAreaControllerRoute` adds a conventional route for controllers in an area.
* `MapControllerRoute` adds a conventional route for controllers.
```csharp
public void Configure(IApplicationBuilder app)
{
...
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapAreaControllerRoute(
"admin",
"admin",
"Admin/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
"default", "{controller=Home}/{action=Index}/{id?}");
});
}
```
### Razor Pages
Mapping Razor Pages now takes place inside `UseEndpoints`.
Add `MapRazorPages` if the app uses Razor Pages. Since Endpoint Routing includes support for many frameworks, adding Razor Pages is now opt-in.
In the following example, `MapRazorPages` adds support for Razor Pages:
```csharp
public void Configure(IApplicationBuilder app)
{
...
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
}
```
### 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.
If the app requires legacy `IRouter` support, disable `EnableEndpointRouting` using any of the following approaches in `Startup.ConfigureServices`:
```csharp
services.AddMvc(options => options.EnableEndpointRouting = false);
```
```csharp
services.AddControllers(options => options.EnableEndpointRouting = false);
```
```csharp
services.AddControllersWithViews(options => options.EnableEndpointRouting = false);
```
```csharp
services.AddRazorPages().AddMvcOptions(options => options.EnableEndpointRouting = false);
```
### Health checks
Health checks can be used as a *router-ware* with Endpoint Routing.
Add `MapHealthChecks` to use health checks with Endpoint Routing. The `MapHealthChecks` method accepts arguments similar to `UseHealthChecks`. The advantage of using `MapHealthChecks` over `UseHealthChecks` is the ability to apply authorization and to have greater fine-grained control over the matching policy.
In the following example, `MapHealthChecks` is called for a health check endpoint at `/healthz`:
```csharp
public void Configure(IApplicationBuilder app)
{
...
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/healthz", new HealthCheckOptions() { });
});
}
```
## HostBuilder replaces WebHostBuilder
The ASP.NET Core 3.0 templates use [Generic Host](xref:fundamentals/host/generic-host). Previous versions used [Web Host](xref:fundamentals/host/web-host). The following code shows the ASP.NET Core 3.0 template generated `Program` class:
[!code-csharp[](22-to-30/samples/Program.cs?name=snippet)]
The following code shows the ASP.NET Core 2.2 template-generated `Program` class:
[!code-csharp[](22-to-30/samples/Program2.2.cs?name=snippet)]
remains in 3.0 and is the type of the `webBuilder` seen in the preceding code sample. will be deprecated in a future release and replaced by `HostBuilder`.
The most significant change from `WebHostBuilder` to `HostBuilder` is in [dependency injection (DI)](xref:fundamentals/dependency-injection). When using `HostBuilder`, you can only inject and into `Startup`'s constructor. The `HostBuilder` DI constraints:
* Enable the DI container to be built only one time.
* Avoids the resulting object lifetime issues like resolving multiple instances of singletons.
## AddAuthorization moved to a different assembly
The ASP.NET Core 2.2 and lower `AddAuthorization` methods in *Microsoft.AspNetCore.Authorization.dll*:
* Have been renamed `AddAuthorizationCore`.
* Have been moved to *Microsoft.AspNetCore.Authorization.Policy.dll*.
Apps that are using both *Microsoft.AspNetCore.Authorization.dll* and *Microsoft.AspNetCore.Authorization.Policy.dll* are not impacted.
Apps that are not using *Microsoft.AspNetCore.Authorization.Policy.dll* should do one of the following:
* Switch to using `AddAuthorizationCore`
* Add a reference to *Microsoft.AspNetCore.Authorization.Policy.dll*.
For more information, see [Breaking change in `AddAuthorization(o =>`) overload lives in a different assembly #386](https://github.com/aspnet/Announcements/issues/386).
## SignalR code
The SignalR JavaScript client has changed from `@aspnet/signalr` to `@microsoft/signalr`. To react to this change, change the references in *package.json* files, require statements, and ECMAScript import statements.
### System.Text.Json is the default protocol
`System.Text.Json` is now the default Hub protocol used by both the client and server.
In `Startup.ConfigureServices`, call `AddJsonProtocol` to set serializer options.
**Server:**
```csharp
services.AddSignalR(...)
.AddJsonProtocol(options =>
{
options.WriteIndented = false;
})
```
**Client:**
```csharp
new HubConnectionBuilder()
.WithUrl("/chatHub")
.AddJsonProtocol(options =>
{
options.WriteIndented = false;
})
.Build();
```
### Switch to Newtonsoft.Json
If you're using features of `Newtonsoft.Json` that aren't supported in `System.Text.Json`, you can switch back to `Newtonsoft.Json`:
1. Install the [Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson](https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson) NuGet package.
1. On the client, chain an `AddNewtonsoftJsonProtocol` method call to the `HubConnectionBuilder` instance:
```csharp
new HubConnectionBuilder()
.WithUrl("/chatHub")
.AddNewtonsoftJsonProtocol(...)
.Build();
```
1. On the server, chain an `AddNewtonsoftJsonProtocol` method call to the `AddSignalR` method call in `Startup.ConfigureServices`:
```csharp
services.AddSignalR()
.AddNewtonsoftJsonProtocol(...);
```
## Opt in to runtime compilation
In 3.0, runtime compilation is an opt-in scenario. To enable runtime compilation, see .
## Migrating libraries via multi-targeting
Libraries often need to support multiple versions of ASP.NET Core. Most libraries that were compiled against previous versions of ASP.NET Core should continue working without issues. The following conditions require the app to be cross compiled:
* The library relies on a feature that has a binary [breaking change](#breaking-api-changes).
* The library wants to take advantage of new features in ASP.NET Core 3.0.
For example:
```xml
netcoreapp3.0;netstandard2.0
```
Use `#ifdefs` to light up ASP.NET Core 3.0 specific APIs:
```csharp
var webRootFileProvider =
#if NETCOREAPP3_0
GetRequiredService().WebRootFileProvider;
#else if NETSTANDARD2_0
GetRequiredService().WebRootFileProvider;
#else
#error unknown target framework
#endif
```
## Breaking API changes
For additional breaking changes in the ASP.NET Core 3.0 release, see the [aspnet/Announcements repository](https://github.com/aspnet/Announcements/issues?page=2&q=is%3Aissue+is%3Aopen+label%3A%22Breaking+change%22+label%3A3.0.0). For a summary of 2.2-to-3.0 breaking changes across .NET Core, ASP.NET Core, and Entity Framework Core, see [Breaking changes for migration from version 2.2 to 3.0](/dotnet/core/compatibility/2.2-3.0).
## ASP.NET Core 3.0 not currently available for Azure App Service.
We hope to make this available soon. Until ASP.NET Core 3.0 is available on Azure App Service, follow the instructions at [Deploy ASP.NET Core preview release to Azure App Service](xref:host-and-deploy/azure-apps/index#deploy-aspnet-core-preview-release-to-azure-app-service).