Skip to content

Commit f29a124

Browse files
Merge pull request #17804 from dotnet/master
Merge to live April 14
2 parents a727210 + 317f8d5 commit f29a124

3 files changed

Lines changed: 59 additions & 25 deletions

File tree

aspnetcore/fundamentals/host/generic-host.md

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ uid: fundamentals/host/generic-host
1212

1313
::: moniker range=">= aspnetcore-3.0 <= aspnetcore-3.1"
1414

15-
This article introduces the .NET Core Generic Host (<xref:Microsoft.Extensions.Hosting.HostBuilder>) and provides guidance on how to use it.
15+
The ASP.NET Core templates create a .NET Core Generic Host (<xref:Microsoft.Extensions.Hosting.HostBuilder>).
1616

17-
## What's a host?
17+
## Host definition
1818

1919
A *host* is an object that encapsulates an app's resources, such as:
2020

@@ -27,16 +27,33 @@ When a host starts, it calls `IHostedService.StartAsync` on each implementation
2727

2828
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.
2929

30-
In versions of ASP.NET Core earlier than 3.0, the [Web Host](xref:fundamentals/host/web-host) is used for HTTP workloads. The Web Host is no longer recommended for web apps and remains available only for backward compatibility.
31-
3230
## Set up a host
3331

3432
The host is typically configured, built, and run by code in the `Program` class. The `Main` method:
3533

3634
* Calls a `CreateHostBuilder` method to create and configure a builder object.
3735
* Calls `Build` and `Run` methods on the builder object.
3836

39-
Here's *Program.cs* code for a non-HTTP workload, with a single `IHostedService` implementation added to the DI container.
37+
The ASP.NET Core web templates generate the following code to create a host:
38+
39+
```csharp
40+
public class Program
41+
{
42+
public static void Main(string[] args)
43+
{
44+
CreateHostBuilder(args).Build().Run();
45+
}
46+
47+
public static IHostBuilder CreateHostBuilder(string[] args) =>
48+
Host.CreateDefaultBuilder(args)
49+
.ConfigureWebHostDefaults(webBuilder =>
50+
{
51+
webBuilder.UseStartup<Startup>();
52+
});
53+
}
54+
```
55+
56+
The following code creates a non-HTTP workload with a `IHostedService` implementation added to the DI container.
4057

4158
```csharp
4259
public class Program
@@ -132,7 +149,7 @@ Inject the <xref:Microsoft.Extensions.Hosting.IHostEnvironment> service into a c
132149

133150
* [ApplicationName](#applicationname)
134151
* [EnvironmentName](#environmentname)
135-
* [ContentRootPath](#contentrootpath)
152+
* [ContentRootPath](#contentroot)
136153

137154
Web apps implement the `IWebHostEnvironment` interface, which inherits `IHostEnvironment` and adds the [WebRootPath](#webroot).
138155

@@ -175,7 +192,7 @@ The [IHostEnvironment.ApplicationName](xref:Microsoft.Extensions.Hosting.IHostEn
175192

176193
To set this value, use the environment variable.
177194

178-
### ContentRootPath
195+
### ContentRoot
179196

180197
The [IHostEnvironment.ContentRootPath](xref:Microsoft.Extensions.Hosting.IHostEnvironment.ContentRootPath*) property determines where the host begins searching for content files. If the path doesn't exist, the host fails to start.
181198

@@ -391,14 +408,14 @@ Kestrel has its own endpoint configuration API. For more information, see <xref:
391408

392409
### WebRoot
393410

394-
The relative path to the app's static assets.
411+
The [IWebHostEnvironment.WebRootPath](xref:Microsoft.AspNetCore.Hosting.IWebHostEnvironment.WebRootPath) property determines the relative path to the app's static assets. If the path doesn't exist, a no-op file provider is used.
395412

396413
**Key**: `webroot`
397414
**Type**: `string`
398-
**Default**: The default is `wwwroot`. The path to *{content root}/wwwroot* must exist. If the path doesn't exist, a no-op file provider is used.
415+
**Default**: The default is `wwwroot`. The path to *{content root}/wwwroot* must exist.
399416
**Environment variable**: `<PREFIX_>WEBROOT`
400417

401-
To set this value, use the environment variable or call `UseWebRoot`:
418+
To set this value, use the environment variable or call `UseWebRoot` on `IWebHostBuilder`:
402419

403420
```csharp
404421
webBuilder.UseWebRoot("public");
@@ -407,7 +424,7 @@ webBuilder.UseWebRoot("public");
407424
For more information, see:
408425

409426
* [Fundamentals: Web root](xref:fundamentals/index#web-root)
410-
* [ContentRootPath](#contentrootpath)
427+
* [ContentRoot](#contentroot)
411428

412429
## Manage the host lifetime
413430

@@ -970,9 +987,9 @@ public class MyClass
970987

971988
::: moniker range=">= aspnetcore-5.0"
972989

973-
This article introduces the .NET Core Generic Host (<xref:Microsoft.Extensions.Hosting.HostBuilder>) and provides guidance on how to use it.
990+
The ASP.NET Core templates create a .NET Core Generic Host (<xref:Microsoft.Extensions.Hosting.HostBuilder>).
974991

975-
## What's a host?
992+
## Host definition
976993

977994
A *host* is an object that encapsulates an app's resources, such as:
978995

@@ -985,16 +1002,33 @@ When a host starts, it calls `IHostedService.StartAsync` on each implementation
9851002

9861003
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.
9871004

988-
In versions of ASP.NET Core earlier than 3.0, the [Web Host](xref:fundamentals/host/web-host) is used for HTTP workloads. The Web Host is no longer recommended for web apps and remains available only for backward compatibility.
989-
9901005
## Set up a host
9911006

9921007
The host is typically configured, built, and run by code in the `Program` class. The `Main` method:
9931008

9941009
* Calls a `CreateHostBuilder` method to create and configure a builder object.
9951010
* Calls `Build` and `Run` methods on the builder object.
9961011

997-
Here's *Program.cs* code for a non-HTTP workload, with a single `IHostedService` implementation added to the DI container.
1012+
The ASP.NET Core web templates generate the following code to create a host:
1013+
1014+
```csharp
1015+
public class Program
1016+
{
1017+
public static void Main(string[] args)
1018+
{
1019+
CreateHostBuilder(args).Build().Run();
1020+
}
1021+
1022+
public static IHostBuilder CreateHostBuilder(string[] args) =>
1023+
Host.CreateDefaultBuilder(args)
1024+
.ConfigureWebHostDefaults(webBuilder =>
1025+
{
1026+
webBuilder.UseStartup<Startup>();
1027+
});
1028+
}
1029+
```
1030+
1031+
The following code creates a non-HTTP workload with a `IHostedService` implementation added to the DI container.
9981032

9991033
```csharp
10001034
public class Program
@@ -1090,7 +1124,7 @@ Inject the <xref:Microsoft.Extensions.Hosting.IHostEnvironment> service into a c
10901124

10911125
* [ApplicationName](#applicationname)
10921126
* [EnvironmentName](#environmentname)
1093-
* [ContentRootPath](#contentrootpath)
1127+
* [ContentRootPath](#contentroot)
10941128

10951129
Web apps implement the `IWebHostEnvironment` interface, which inherits `IHostEnvironment` and adds the [WebRootPath](#webroot).
10961130

@@ -1133,7 +1167,7 @@ The [IHostEnvironment.ApplicationName](xref:Microsoft.Extensions.Hosting.IHostEn
11331167

11341168
To set this value, use the environment variable.
11351169

1136-
### ContentRootPath
1170+
### ContentRoot
11371171

11381172
The [IHostEnvironment.ContentRootPath](xref:Microsoft.Extensions.Hosting.IHostEnvironment.ContentRootPath*) property determines where the host begins searching for content files. If the path doesn't exist, the host fails to start.
11391173

@@ -1362,14 +1396,14 @@ Kestrel has its own endpoint configuration API. For more information, see <xref:
13621396

13631397
### WebRoot
13641398

1365-
The relative path to the app's static assets.
1399+
The [IWebHostEnvironment.WebRootPath](xref:Microsoft.AspNetCore.Hosting.IWebHostEnvironment.WebRootPath) property determines the relative path to the app's static assets. If the path doesn't exist, a no-op file provider is used.
13661400

13671401
**Key**: `webroot`
13681402
**Type**: `string`
1369-
**Default**: The default is `wwwroot`. The path to *{content root}/wwwroot* must exist. If the path doesn't exist, a no-op file provider is used.
1403+
**Default**: The default is `wwwroot`. The path to *{content root}/wwwroot* must exist.
13701404
**Environment variable**: `<PREFIX_>WEBROOT`
13711405

1372-
To set this value, use the environment variable or call `UseWebRoot`:
1406+
To set this value, use the environment variable or call `UseWebRoot` on `IWebHostBuilder`:
13731407

13741408
```csharp
13751409
webBuilder.UseWebRoot("public");
@@ -1378,7 +1412,7 @@ webBuilder.UseWebRoot("public");
13781412
For more information, see:
13791413

13801414
* [Fundamentals: Web root](xref:fundamentals/index#web-root)
1381-
* [ContentRootPath](#contentrootpath)
1415+
* [ContentRoot](#contentroot)
13821416

13831417
## Manage the host lifetime
13841418

aspnetcore/fundamentals/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ The content root is the base path for:
199199
* Data files (*.db*)
200200
* The [Web root](#web-root), typically the *wwwroot* folder.
201201

202-
During development, the content root defaults to the project's root directory. This directory is also the base path for both the app's content files and the [Web root](#web-root). Specify a different content root by setting its path when [building the host](#host). For more information, see [Content root](xref:fundamentals/host/generic-host#contentrootpath-1).
202+
During development, the content root defaults to the project's root directory. This directory is also the base path for both the app's content files and the [Web root](#web-root). Specify a different content root by setting its path when [building the host](#host). For more information, see [Content root](xref:fundamentals/host/generic-host#contentroot).
203203

204204
## Web root
205205

@@ -209,7 +209,7 @@ The web root is the base path for public, static resource files, such as:
209209
* JavaScript (*.js*)
210210
* Images (*.png*, *.jpg*)
211211

212-
By default, static files are served only from the web root directory and its sub-directories. The web root path defaults to *{content root}/wwwroot*. Specify a different web root by setting its path when [building the host](#host). For more information, see [Web root](xref:fundamentals/host/generic-host#webroot-1).
212+
By default, static files are served only from the web root directory and its sub-directories. The web root path defaults to *{content root}/wwwroot*. Specify a different web root by setting its path when [building the host](#host). For more information, see [Web root](xref:fundamentals/host/generic-host#webroot).
213213

214214
Prevent publishing files in *wwwroot* with the [\<Content> project item](/visualstudio/msbuild/common-msbuild-project-items#content) in the project file. The following example prevents publishing content in *wwwroot/local* and its sub-directories:
215215

aspnetcore/security/authentication/social/microsoft-logins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ uid: security/authentication/microsoft-logins
1212

1313
By [Valeriy Novytskyy](https://github.com/01binary) and [Rick Anderson](https://twitter.com/RickAndMSFT)
1414

15-
This sample shows you how to enable users to sign in with their Microsoft account using the ASP.NET Core 3.0 project created on the [previous page](xref:security/authentication/social/index).
15+
This sample shows you how to enable users to sign in with their work, school, or personal Microsoft account using the ASP.NET Core 3.0 project created on the [previous page](xref:security/authentication/social/index).
1616

1717
## Create the app in Microsoft Developer Portal
1818

0 commit comments

Comments
 (0)