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/blazor/host-and-deploy/index.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,6 +52,12 @@ Publish locations:
52
52
53
53
The assets in the folder are deployed to the web server. Deployment might be a manual or automated process depending on the development tools in use.
54
54
55
+
## IIS Application Pools
56
+
57
+
Sharing an app pool among ASP.NET Core apps isn't supported, including for Blazor apps. Use one app pool per app when hosting with IIS, and avoid the use of IIS's [virtual directories](/iis/get-started/planning-your-iis-architecture/understanding-sites-applications-and-virtual-directories-on-iis#virtual-directories) for hosting multiple apps.
58
+
59
+
One or more Blazor WebAssembly apps hosted by an ASP.NET Core app, known as a [hosted Blazor WebAssembly solution](xref:blazor/hosting-models#blazor-webassembly), are supported for ***one*** app pool. However, we don't recommend or support assigning a single app pool to multiple hosted Blazor WebAssembly solutions or in sub-app hosting scenarios. For more information, see <xref:host-and-deploy/iis/advanced#sub-applications>.
60
+
55
61
## App base path
56
62
57
63
The *app base path* is the app's root URL path. Consider the following ASP.NET Core app and Blazor sub-app:
@@ -211,6 +217,12 @@ Publish locations:
211
217
212
218
The assets in the folder are deployed to the web server. Deployment might be a manual or automated process depending on the development tools in use.
213
219
220
+
## IIS Application Pools
221
+
222
+
Sharing an app pool among ASP.NET Core apps isn't supported, including for Blazor apps. Use one app pool per app when hosting with IIS, and avoid the use of IIS's [virtual directories](/iis/get-started/planning-your-iis-architecture/understanding-sites-applications-and-virtual-directories-on-iis#virtual-directories) for hosting multiple apps.
223
+
224
+
One or more Blazor WebAssembly apps hosted by an ASP.NET Core app, known as a [hosted Blazor WebAssembly solution](xref:blazor/hosting-models#blazor-webassembly), are supported for ***one*** app pool. However, we don't recommend or support assigning a single app pool to multiple hosted Blazor WebAssembly solutions or in sub-app hosting scenarios. For more information, see <xref:host-and-deploy/iis/advanced#sub-applications>.
225
+
214
226
## App base path
215
227
216
228
The *app base path* is the app's root URL path. Consider the following ASP.NET Core app and Blazor sub-app:
@@ -350,6 +362,12 @@ Publish locations:
350
362
351
363
The assets in the folder are deployed to the web server. Deployment might be a manual or automated process depending on the development tools in use.
352
364
365
+
## IIS Application Pools
366
+
367
+
Sharing an app pool among ASP.NET Core apps isn't supported, including for Blazor apps. Use one app pool per app when hosting with IIS, and avoid the use of IIS's [virtual directories](/iis/get-started/planning-your-iis-architecture/understanding-sites-applications-and-virtual-directories-on-iis#virtual-directories) for hosting multiple apps.
368
+
369
+
One or more Blazor WebAssembly apps hosted by an ASP.NET Core app, known as a [hosted Blazor WebAssembly solution](xref:blazor/hosting-models#blazor-webassembly), are supported for ***one*** app pool. However, we don't recommend or support assigning a single app pool to multiple hosted Blazor WebAssembly solutions or in sub-app hosting scenarios. For more information, see <xref:host-and-deploy/iis/advanced#sub-applications>.
370
+
353
371
## App base path
354
372
355
373
The *app base path* is the app's root URL path. Consider the following ASP.NET Core app and Blazor sub-app:
The ASP.NET Core templates create a .NET Core Generic Host (<xref:Microsoft.Extensions.Hosting.HostBuilder>).
16
+
This article provides information on using the .NET Generic Host in ASP.NET Core.
17
17
18
-
This article provides information on using .NET Generic Host in ASP.NET Core. For information on using .NET Generic Host in console apps, see [.NET Generic Host](/dotnet/core/extensions/generic-host).
18
+
The ASP.NET Core templates create a <xref:Microsoft.AspNetCore.Builder.WebApplicationBuilder> and <xref:Microsoft.AspNetCore.Builder.WebApplication>, which provide a streamlined way to configure and run web applications without a `Startup` class. For more information on `WebApplicationBuilder` and `WebApplication`, see <xref:migration/50-to-60#new-hosting-model>.
19
+
20
+
For information on using the .NET Generic Host in console apps, see [.NET Generic Host](/dotnet/core/extensions/generic-host).
19
21
20
22
## Host definition
21
23
@@ -28,65 +30,17 @@ A *host* is an object that encapsulates an app's resources, such as:
28
30
29
31
When a host starts, it calls <xref:Microsoft.Extensions.Hosting.IHostedService.StartAsync%2A?displayProperty=nameWithType> on each implementation of <xref:Microsoft.Extensions.Hosting.IHostedService> registered in the service container's collection of hosted services. In a web app, one of the `IHostedService` implementations is a web service that starts an [HTTP server implementation](xref:fundamentals/index#servers).
30
32
31
-
The main reason for including all of the app's interdependent resources in one object is lifetime management: control over app startup and graceful shutdown.
33
+
Including all of the app's interdependent resources in one object enables control over app startup and graceful shutdown.
32
34
33
35
## Set up a host
34
36
35
-
The host is typically configured, built, and run by code in the `Program` class. The `Main` method:
36
-
37
-
* Calls a `CreateHostBuilder` method to create and configure a builder object.
38
-
* Calls `Build` and `Run` methods on the builder object.
39
-
40
-
The ASP.NET Core web templates generate the following code to create a host:
37
+
The host is typically configured, built, and run by code in the *Program.cs*. The following code creates a host with an `IHostedService` implementation added to the DI container:
The following code creates a non-HTTP workload with an `IHostedService` implementation added to the DI container.
41
+
For an HTTP workload, call <xref:Microsoft.Extensions.Hosting.GenericHostBuilderExtensions.ConfigureWebHostDefaults%2A> after <xref:Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder%2A>:
If the app uses Entity Framework Core, don't change the name or signature of the `CreateHostBuilder` method. The [Entity Framework Core tools](/ef/core/miscellaneous/cli/) expect to find a `CreateHostBuilder` method that configures the host without running the app. For more information, see [Design-time DbContext Creation](/ef/core/miscellaneous/cli/dbcontext-creation).
@@ -131,11 +85,17 @@ For more information on framework-provided services, see <xref:fundamentals/depe
131
85
132
86
## IHostApplicationLifetime
133
87
134
-
Inject the <xref:Microsoft.Extensions.Hosting.IHostApplicationLifetime> (formerly `IApplicationLifetime`) service into any class to handle post-startup and graceful shutdown tasks. Three properties on the interface are cancellation tokens used to register app start and app stop event handler methods. The interface also includes a `StopApplication` method.
88
+
Inject the <xref:Microsoft.Extensions.Hosting.IHostApplicationLifetime> (formerly `IApplicationLifetime`) service into any class to handle post-startup and graceful shutdown tasks. Three properties on the interface are cancellation tokens used to register app start and app stop event handler methods. The interface also includes a `StopApplication` method, which allows apps to request a graceful shutdown.
135
89
136
-
The following example is an `IHostedService` implementation that registers `IHostApplicationLifetime` events:
* Triggers the <xref:Microsoft.Extensions.Hosting.IHostApplicationLifetime.ApplicationStopping%2A> event handlers, which allows the app to run logic before the shutdown process begins.
93
+
* Stops the server, which disables new connections. The server waits for requests on existing connections to complete, for as long as the [shutdown timeout](#shutdowntimeout) allows. The server sends the connection close header for further requests on existing connections.
94
+
* Triggers the <xref:Microsoft.Extensions.Hosting.IHostApplicationLifetime.ApplicationStopped%2A> event handlers, which allows the app to run logic after the application has shutdown.
95
+
96
+
The following example is an `IHostedService` implementation that registers `IHostApplicationLifetime` event handlers:
@@ -271,15 +223,7 @@ Some host settings apply only to HTTP workloads. By default, environment variabl
271
223
272
224
Extension methods on `IWebHostBuilder` are available for these settings. Code samples that show how to call the extension methods assume `webBuilder` is an instance of `IWebHostBuilder`, as in the following example:
@@ -397,13 +327,8 @@ The assembly to search for the `Startup` class.
397
327
398
328
To set this value, use the environment variable or call `UseStartup`. `UseStartup` can take an assembly name (`string`) or a type (`TStartup`). If multiple `UseStartup` methods are called, the last one takes precedence.
@@ -495,36 +414,6 @@ Call methods on the built <xref:Microsoft.Extensions.Hosting.IHost> implementati
495
414
496
415
<xref:Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.WaitForShutdownAsync%2A> returns a <xref:System.Threading.Tasks.Task> that completes when shutdown is triggered via the given token and calls <xref:Microsoft.Extensions.Hosting.IHost.StopAsync%2A>.
497
416
498
-
### External control
499
-
500
-
Direct control of the host lifetime can be achieved using methods that can be called externally:
0 commit comments