Improve Kestrel startup example (#16269)
parent
c9794fca44
commit
a8595be006
|
@ -5,7 +5,7 @@ description: Learn about Kestrel, the cross-platform web server for ASP.NET Core
|
|||
monikerRange: '>= aspnetcore-2.1'
|
||||
ms.author: riande
|
||||
ms.custom: mvc
|
||||
ms.date: 11/14/2019
|
||||
ms.date: 12/18/2019
|
||||
uid: fundamentals/servers/kestrel
|
||||
---
|
||||
# Kestrel web server implementation in ASP.NET Core
|
||||
|
@ -130,15 +130,30 @@ Use **one** of the following approaches:
|
|||
* Configure Kestrel in `Startup.ConfigureServices`:
|
||||
|
||||
1. Inject an instance of `IConfiguration` into the `Startup` class. The following example assumes that the injected configuration is assigned to the `Configuration` property.
|
||||
2. In `Startup.ConfigureServices`, load the `Kestrel` section of configuration into Kestrel's configuration.
|
||||
2. In `Startup.ConfigureServices`, load the `Kestrel` section of configuration into Kestrel's configuration:
|
||||
|
||||
```csharp
|
||||
// using Microsoft.Extensions.Configuration
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
using Microsoft.Extensions.Configuration
|
||||
|
||||
public class Startup
|
||||
{
|
||||
services.Configure<KestrelServerOptions>(
|
||||
Configuration.GetSection("Kestrel"));
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.Configure<KestrelServerOptions>(
|
||||
Configuration.GetSection("Kestrel"));
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -1084,15 +1099,30 @@ Use **one** of the following approaches:
|
|||
* Configure Kestrel in `Startup.ConfigureServices`:
|
||||
|
||||
1. Inject an instance of `IConfiguration` into the `Startup` class. The following example assumes that the injected configuration is assigned to the `Configuration` property.
|
||||
2. In `Startup.ConfigureServices`, load the `Kestrel` section of configuration into Kestrel's configuration.
|
||||
2. In `Startup.ConfigureServices`, load the `Kestrel` section of configuration into Kestrel's configuration:
|
||||
|
||||
```csharp
|
||||
// using Microsoft.Extensions.Configuration
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
using Microsoft.Extensions.Configuration
|
||||
|
||||
public class Startup
|
||||
{
|
||||
services.Configure<KestrelServerOptions>(
|
||||
Configuration.GetSection("Kestrel"));
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.Configure<KestrelServerOptions>(
|
||||
Configuration.GetSection("Kestrel"));
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -1974,15 +2004,30 @@ Use **one** of the following approaches:
|
|||
* Configure Kestrel in `Startup.ConfigureServices`:
|
||||
|
||||
1. Inject an instance of `IConfiguration` into the `Startup` class. The following example assumes that the injected configuration is assigned to the `Configuration` property.
|
||||
2. In `Startup.ConfigureServices`, load the `Kestrel` section of configuration into Kestrel's configuration.
|
||||
2. In `Startup.ConfigureServices`, load the `Kestrel` section of configuration into Kestrel's configuration:
|
||||
|
||||
```csharp
|
||||
// using Microsoft.Extensions.Configuration
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
using Microsoft.Extensions.Configuration
|
||||
|
||||
public class Startup
|
||||
{
|
||||
services.Configure<KestrelServerOptions>(
|
||||
Configuration.GetSection("Kestrel"));
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.Configure<KestrelServerOptions>(
|
||||
Configuration.GetSection("Kestrel"));
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue