parent
9cf3e6ed15
commit
91a2e221a9
|
@ -177,11 +177,17 @@ The maximum number of concurrent open TCP connections can be set for the entire
|
|||
|
||||
::: moniker range=">= aspnetcore-2.2"
|
||||
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_Limits&highlight=3)]
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1"
|
||||
|
||||
```csharp
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureKestrel((context, options) =>
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Limits.MaxConcurrentConnections = 100;
|
||||
});
|
||||
|
@ -189,21 +195,21 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
|||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1"
|
||||
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_Limits&highlight=3)]
|
||||
|
||||
::: moniker-end
|
||||
|
||||
There's a separate limit for connections that have been upgraded from HTTP or HTTPS to another protocol (for example, on a WebSockets request). After a connection is upgraded, it isn't counted against the `MaxConcurrentConnections` limit.
|
||||
|
||||
::: moniker range=">= aspnetcore-2.2"
|
||||
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_Limits&highlight=4)]
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1"
|
||||
|
||||
```csharp
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureKestrel((context, options) =>
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Limits.MaxConcurrentUpgradedConnections = 100;
|
||||
});
|
||||
|
@ -211,12 +217,6 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
|||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1"
|
||||
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_Limits&highlight=4)]
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range=">= aspnetcore-2.0"
|
||||
|
||||
The maximum number of connections is unlimited (null) by default.
|
||||
|
@ -240,21 +240,21 @@ Here's an example that shows how to configure the constraint for the app on ever
|
|||
|
||||
::: moniker range=">= aspnetcore-2.2"
|
||||
|
||||
```csharp
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
options.Limits.MaxRequestBodySize = 10 * 1024;
|
||||
});
|
||||
```
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_Limits&highlight=5)]
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1"
|
||||
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_Limits&highlight=5)]
|
||||
```csharp
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Limits.MaxRequestBodySize = 10 * 1024;
|
||||
});
|
||||
```
|
||||
|
||||
You can override the setting on a specific request in middleware:
|
||||
|
||||
|
@ -283,11 +283,17 @@ Here's an example that shows how to configure the minimum data rates in *Program
|
|||
|
||||
::: moniker range=">= aspnetcore-2.2"
|
||||
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_Limits&highlight=6-9)]
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1"
|
||||
|
||||
```csharp
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureKestrel((context, options) =>
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Limits.MinRequestBodyDataRate =
|
||||
new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));
|
||||
|
@ -296,12 +302,6 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
|||
});
|
||||
```
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1"
|
||||
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_Limits&highlight=6-9)]
|
||||
|
||||
You can configure the rates per request in middleware:
|
||||
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Startup.cs?name=snippet_Limits&highlight=5-8)]
|
||||
|
@ -437,10 +437,6 @@ Specifies a configuration `Action` to run for each HTTPS endpoint. Calling `Conf
|
|||
|
||||
Creates a configuration loader for setting up Kestrel that takes an [IConfiguration](/dotnet/api/microsoft.extensions.configuration.iconfiguration) as input. The configuration must be scoped to the configuration section for Kestrel.
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range=">= aspnetcore-2.1"
|
||||
|
||||
### ListenOptions.UseHttps
|
||||
|
||||
Configure Kestrel to use HTTPS.
|
||||
|
@ -707,6 +703,12 @@ The [Listen](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelservero
|
|||
|
||||
::: moniker range=">= aspnetcore-2.2"
|
||||
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_TCPSocket&highlight=9-16)]
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1"
|
||||
|
||||
```csharp
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
@ -716,10 +718,10 @@ public static void Main(string[] args)
|
|||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureKestrel((context, options) =>
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, 8000);
|
||||
options.Listen(IPAddress.Loopback, 8001, listenOptions =>
|
||||
options.Listen(IPAddress.Loopback, 5000);
|
||||
options.Listen(IPAddress.Loopback, 5001, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps("testCert.pfx", "testPassword");
|
||||
});
|
||||
|
@ -728,12 +730,6 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
|||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1"
|
||||
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_TCPSocket&highlight=9-16)]
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range=">= aspnetcore-2.0"
|
||||
|
||||
The example configures SSL for an endpoint with [ListenOptions](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.listenoptions). Use the same API to configure other Kestrel settings for specific endpoints.
|
||||
|
@ -748,11 +744,17 @@ Listen on a Unix socket with [ListenUnixSocket](/dotnet/api/microsoft.aspnetcore
|
|||
|
||||
::: moniker range=">= aspnetcore-2.2"
|
||||
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_UnixSocket)]
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1"
|
||||
|
||||
```csharp
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureKestrel((context, options) =>
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.ListenUnixSocket("/tmp/kestrel-test.sock");
|
||||
options.ListenUnixSocket("/tmp/kestrel-test.sock", listenOptions =>
|
||||
|
@ -764,12 +766,6 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
|||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1"
|
||||
|
||||
[!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_UnixSocket)]
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range=">= aspnetcore-2.0"
|
||||
|
||||
### Port 0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#define DefaultBuilder
|
||||
// or any of: Limits TCPSocket UnixSocket FileDescriptor Port0
|
||||
// TCPSocket UnixSocket FileDescriptor Limits require a PFX X.509 certificate
|
||||
// Define any of the following for the scenarios described in the Kestrel topic:
|
||||
// DefaultBuilder Limits TCPSocket UnixSocket FileDescriptor Port0
|
||||
// The following require an X.509 certificate:
|
||||
// TCPSocket UnixSocket FileDescriptor Limits
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
|
@ -38,10 +40,10 @@ namespace KestrelSample
|
|||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.UseKestrel(options =>
|
||||
.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, 8000);
|
||||
options.Listen(IPAddress.Loopback, 8001, listenOptions =>
|
||||
options.Listen(IPAddress.Loopback, 5000);
|
||||
options.Listen(IPAddress.Loopback, 5001, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps("testCert.pfx", "testPassword");
|
||||
});
|
||||
|
@ -57,7 +59,7 @@ namespace KestrelSample
|
|||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
#region snippet_UnixSocket
|
||||
.UseKestrel(options =>
|
||||
.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
options.ListenUnixSocket("/tmp/kestrel-test.sock");
|
||||
options.ListenUnixSocket("/tmp/kestrel-test.sock", listenOptions =>
|
||||
|
@ -76,7 +78,7 @@ namespace KestrelSample
|
|||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
#region snippet_FileDescriptor
|
||||
.UseKestrel(options =>
|
||||
.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
var fds = Environment.GetEnvironmentVariable("SD_LISTEN_FDS_START");
|
||||
ulong fd = ulong.Parse(fds);
|
||||
|
@ -98,7 +100,7 @@ namespace KestrelSample
|
|||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
#region snippet_Limits
|
||||
.UseKestrel(options =>
|
||||
.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
options.Limits.MaxConcurrentConnections = 100;
|
||||
options.Limits.MaxConcurrentUpgradedConnections = 100;
|
||||
|
@ -124,7 +126,7 @@ namespace KestrelSample
|
|||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
#region snippet_Port0
|
||||
.UseKestrel(options =>
|
||||
.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, 0);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue