diff --git a/aspnetcore/fundamentals/host/web-host.md b/aspnetcore/fundamentals/host/web-host.md index 0150f6397730..6017fe4b0435 100644 --- a/aspnetcore/fundamentals/host/web-host.md +++ b/aspnetcore/fundamentals/host/web-host.md @@ -2,21 +2,22 @@ title: ASP.NET Core Web Host author: guardrex description: Learn about the web host in ASP.NET Core, which is responsible for app startup and lifetime management. +monikerRange: '>= aspnetcore-2.1' ms.author: riande ms.custom: mvc -ms.date: 10/18/2018 +ms.date: 11/05/2018 uid: fundamentals/host/web-host --- # ASP.NET Core Web Host By [Luke Latham](https://github.com/guardrex) +For the 1.1 version of this topic, download [ASP.NET Core Web Host (version 1.1, PDF)](https://webpifeed.blob.core.windows.net/webpifeed/Partners/Web-Host_1.1.pdf). + ASP.NET Core apps configure and launch a *host*. The host is responsible for app startup and lifetime management. At a minimum, the host configures a server and a request processing pipeline. This topic covers the ASP.NET Core Web Host ([IWebHostBuilder](/dotnet/api/microsoft.aspnetcore.hosting.iwebhostbuilder)), which is useful for hosting web apps. For coverage of the .NET Generic Host ([IHostBuilder](/dotnet/api/microsoft.extensions.hosting.ihostbuilder)), see . ## Set up a host -::: moniker range=">= aspnetcore-2.0" - Create a host using an instance of [IWebHostBuilder](/dotnet/api/microsoft.aspnetcore.hosting.iwebhostbuilder). This is typically performed in the app's entry point, the `Main` method. In the project templates, `Main` is located in *Program.cs*. A typical *Program.cs* calls [CreateDefaultBuilder](/dotnet/api/microsoft.aspnetcore.webhost.createdefaultbuilder) to start setting up a host: ```csharp @@ -74,8 +75,6 @@ The configuration defined by `CreateDefaultBuilder` can be overridden and augmen ... ``` -::: moniker-end - ::: moniker range=">= aspnetcore-2.2" * The following call to `ConfigureKestrel` overrides the default [Limits.MaxRequestBodySize](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserverlimits.maxrequestbodysize) of 30,000,000 bytes established when Kestrel was configured by `CreateDefaultBuilder`: @@ -86,12 +85,11 @@ The configuration defined by `CreateDefaultBuilder` can be overridden and augmen { options.Limits.MaxRequestBodySize = 20000000; }); - ... ``` ::: moniker-end -::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1" +::: moniker range="< aspnetcore-2.2" * The following call to [UseKestrel](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilderkestrelextensions.usekestrel) overrides the default [Limits.MaxRequestBodySize](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserverlimits.maxrequestbodysize) of 30,000,000 bytes established when Kestrel was configured by `CreateDefaultBuilder`: @@ -101,13 +99,10 @@ The configuration defined by `CreateDefaultBuilder` can be overridden and augmen { options.Limits.MaxRequestBodySize = 20000000; }); - ... ``` ::: moniker-end -::: moniker range=">= aspnetcore-2.0" - The *content root* determines where the host searches for content files, such as MVC view files. When the app is started from the project's root folder, the project's root folder is used as the content root. This is the default used in [Visual Studio](https://www.visualstudio.com/) and the [dotnet new templates](/dotnet/core/tools/dotnet-new). For more information on app configuration, see . @@ -115,49 +110,6 @@ For more information on app configuration, see [!NOTE] > As an alternative to using the static `CreateDefaultBuilder` method, creating a host from [WebHostBuilder](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilder) is a supported approach with ASP.NET Core 2.x. For more information, see the ASP.NET Core 1.x tab. -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -Create a host using an instance of [WebHostBuilder](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilder). Creating a host is typically performed in the app's entry point, the `Main` method. In the project templates, `Main` is located in *Program.cs*: - -```csharp -public class Program -{ - public static void Main(string[] args) - { - BuildWebHost(args).Run(); - } - - public static IWebHost BuildWebHost(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup() - .Build(); -} -``` - -`WebHostBuilder` requires a [server that implements IServer](xref:fundamentals/servers/index). The built-in servers are [Kestrel](xref:fundamentals/servers/kestrel) and [HTTP.sys](xref:fundamentals/servers/httpsys) (prior to the release of ASP.NET Core 2.0, HTTP.sys was called [WebListener](xref:fundamentals/servers/weblistener)). In this example, the [UseKestrel extension method](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilderkestrelextensions.usekestrel?view=aspnetcore-1.1) specifies the Kestrel server. - -The *content root* determines where the host searches for content files, such as MVC view files. The default content root is obtained for `UseContentRoot` by [Directory.GetCurrentDirectory](/dotnet/api/system.io.directory.getcurrentdirectory?view=netcore-1.1). When the app is started from the project's root folder, the project's root folder is used as the content root. This is the default used in [Visual Studio](https://www.visualstudio.com/) and the [dotnet new templates](/dotnet/core/tools/dotnet-new). - -To use IIS as a reverse proxy, call [UseIISIntegration](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilderiisextensions) as part of building the host. `UseIISIntegration` doesn't configure a *server*, like [UseKestrel](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilderkestrelextensions.usekestrel?view=aspnetcore-1.1) does. `UseIISIntegration` configures the base path and port the server listens on when using the [ASP.NET Core Module](xref:fundamentals/servers/aspnet-core-module) to create a reverse proxy between Kestrel and IIS. To use IIS with ASP.NET Core, `UseKestrel` and `UseIISIntegration` must be specified. `UseIISIntegration` only activates when running behind IIS or IIS Express. For more information, see and . - -A minimal implementation that configures a host (and an ASP.NET Core app) includes specifying a server and configuration of the app's request pipeline: - -```csharp -var host = new WebHostBuilder() - .UseKestrel() - .Configure(app => - { - app.Run(context => context.Response.WriteAsync("Hello World!")); - }) - .Build(); - -host.Run(); -``` - -::: moniker-end - When setting up a host, [Configure](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilderextensions.configure?view=aspnetcore-1.1) and [ConfigureServices](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilder.configureservices?view=aspnetcore-1.1) methods can be provided. If a `Startup` class is specified, it must define a `Configure` method. For more information, see . Multiple calls to `ConfigureServices` append to one another. Multiple calls to `Configure` or `UseStartup` on the `WebHostBuilder` replace previous settings. ## Host configuration values @@ -180,24 +132,11 @@ The [IHostingEnvironment.ApplicationName](/dotnet/api/microsoft.extensions.hosti **Set using**: `UseSetting` **Environment variable**: `ASPNETCORE_APPLICATIONNAME` -::: moniker range=">= aspnetcore-2.1" - ```csharp WebHost.CreateDefaultBuilder(args) .UseSetting(WebHostDefaults.ApplicationKey, "CustomApplicationName") ``` -::: moniker-end - -::: moniker range="< aspnetcore-2.1" - -```csharp -var host = new WebHostBuilder() - .UseSetting("applicationName", "CustomApplicationName") -``` - -::: moniker-end - ### Capture Startup Errors This setting controls the capture of startup errors. @@ -210,24 +149,11 @@ This setting controls the capture of startup errors. When `false`, errors during startup result in the host exiting. When `true`, the host captures exceptions during startup and attempts to start the server. -::: moniker range=">= aspnetcore-2.0" - ```csharp WebHost.CreateDefaultBuilder(args) .CaptureStartupErrors(true) ``` -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -```csharp -var host = new WebHostBuilder() - .CaptureStartupErrors(true) -``` - -::: moniker-end - ### Content Root This setting determines where ASP.NET Core begins searching for content files, such as MVC views. @@ -240,24 +166,11 @@ This setting determines where ASP.NET Core begins searching for content files, s The content root is also used as the base path for the [Web Root setting](#web-root). If the path doesn't exist, the host fails to start. -::: moniker range=">= aspnetcore-2.0" - ```csharp WebHost.CreateDefaultBuilder(args) .UseContentRoot("c:\\") ``` -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -```csharp -var host = new WebHostBuilder() - .UseContentRoot("c:\\") -``` - -::: moniker-end - ### Detailed Errors Determines if detailed errors should be captured. @@ -270,24 +183,11 @@ Determines if detailed errors should be captured. When enabled (or when the Environment is set to `Development`), the app captures detailed exceptions. -::: moniker range=">= aspnetcore-2.0" - ```csharp WebHost.CreateDefaultBuilder(args) .UseSetting(WebHostDefaults.DetailedErrorsKey, "true") ``` -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -```csharp -var host = new WebHostBuilder() - .UseSetting(WebHostDefaults.DetailedErrorsKey, "true") -``` - -::: moniker-end - ### Environment Sets the app's environment. @@ -300,26 +200,11 @@ Sets the app's environment. The environment can be set to any value. Framework-defined values include `Development`, `Staging`, and `Production`. Values aren't case sensitive. By default, the *Environment* is read from the `ASPNETCORE_ENVIRONMENT` environment variable. When using [Visual Studio](https://www.visualstudio.com/), environment variables may be set in the *launchSettings.json* file. For more information, see . -::: moniker range=">= aspnetcore-2.0" - ```csharp WebHost.CreateDefaultBuilder(args) .UseEnvironment(EnvironmentName.Development) ``` -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -```csharp -var host = new WebHostBuilder() - .UseEnvironment(EnvironmentName.Development) -``` - -::: moniker-end - -::: moniker range=">= aspnetcore-2.0" - ### Hosting Startup Assemblies Sets the app's hosting startup assemblies. @@ -339,10 +224,6 @@ WebHost.CreateDefaultBuilder(args) .UseSetting(WebHostDefaults.HostingStartupAssembliesKey, "assembly1;assembly2") ``` -::: moniker-end - -::: moniker range=">= aspnetcore-2.1" - ### HTTPS Port Set the HTTPS redirect port. Used in [enforcing HTTPS](xref:security/enforcing-ssl). @@ -373,10 +254,6 @@ WebHost.CreateDefaultBuilder(args) .UseSetting(WebHostDefaults.HostingStartupExcludeAssembliesKey, "assembly1;assembly2") ``` -::: moniker-end - -::: moniker range=">= aspnetcore-2.0" - ### Prefer Hosting URLs Indicates whether the host should listen on the URLs configured with the `WebHostBuilder` instead of those configured with the `IServer` implementation. @@ -392,10 +269,6 @@ WebHost.CreateDefaultBuilder(args) .PreferHostingUrls(false) ``` -::: moniker-end - -::: moniker range=">= aspnetcore-2.0" - ### Prevent Hosting Startup Prevents the automatic loading of hosting startup assemblies, including hosting startup assemblies configured by the app's assembly. For more information, see . @@ -411,8 +284,6 @@ WebHost.CreateDefaultBuilder(args) .UseSetting(WebHostDefaults.PreventHostingStartupKey, "true") ``` -::: moniker-end - ### Server URLs Indicates the IP addresses or host addresses with ports and protocols that the server should listen on for requests. @@ -425,8 +296,6 @@ Indicates the IP addresses or host addresses with ports and protocols that the s Set to a semicolon-separated (;) list of URL prefixes to which the server should respond. For example, `http://localhost:123`. Use "\*" to indicate that the server should listen for requests on any IP address or hostname using the specified port and protocol (for example, `http://*:5000`). The protocol (`http://` or `https://`) must be included with each URL. Supported formats vary between servers. -::: moniker range=">= aspnetcore-2.0" - ```csharp WebHost.CreateDefaultBuilder(args) .UseUrls("http://*:5000;http://localhost:5001;https://hostname:5002") @@ -434,19 +303,6 @@ WebHost.CreateDefaultBuilder(args) Kestrel has its own endpoint configuration API. For more information, see . -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -```csharp -var host = new WebHostBuilder() - .UseUrls("http://*:5000;http://localhost:5001;https://hostname:5002") -``` - -::: moniker-end - -::: moniker range=">= aspnetcore-2.0" - ### Shutdown Timeout Specifies the amount of time to wait for the web host to shut down. @@ -471,8 +327,6 @@ WebHost.CreateDefaultBuilder(args) .UseShutdownTimeout(TimeSpan.FromSeconds(10)) ``` -::: moniker-end - ### Startup Assembly Determines the assembly to search for the `Startup` class. @@ -485,8 +339,6 @@ Determines the assembly to search for the `Startup` class. The assembly by name (`string`) or type (`TStartup`) can be referenced. If multiple `UseStartup` methods are called, the last one takes precedence. -::: moniker range=">= aspnetcore-2.0" - ```csharp WebHost.CreateDefaultBuilder(args) .UseStartup("StartupAssemblyName") @@ -497,22 +349,6 @@ WebHost.CreateDefaultBuilder(args) .UseStartup() ``` -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -```csharp -var host = new WebHostBuilder() - .UseStartup("StartupAssemblyName") -``` - -```csharp -var host = new WebHostBuilder() - .UseStartup() -``` - -::: moniker-end - ### Web Root Sets the relative path to the app's static assets. @@ -523,30 +359,15 @@ Sets the relative path to the app's static assets. **Set using**: `UseWebRoot` **Environment variable**: `ASPNETCORE_WEBROOT` -::: moniker range=">= aspnetcore-2.0" - ```csharp WebHost.CreateDefaultBuilder(args) .UseWebRoot("public") ``` -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -```csharp -var host = new WebHostBuilder() - .UseWebRoot("public") -``` - -::: moniker-end - ## Override configuration Use [Configuration](xref:fundamentals/configuration/index) to configure the web host. In the following example, host configuration is optionally specified in a *hostsettings.json* file. Any configuration loaded from the *hostsettings.json* file may be overridden by command-line arguments. The built configuration (in `config`) is used to configure the host with [UseConfiguration](/dotnet/api/microsoft.aspnetcore.hosting.hostingabstractionswebhostbuilderextensions.useconfiguration). `IWebHostBuilder` configuration is added to the app's configuration, but the converse isn't true—`ConfigureAppConfiguration` doesn't affect the `IWebHostBuilder` configuration. -::: moniker range=">= aspnetcore-2.0" - Overriding the configuration provided by `UseUrls` with *hostsettings.json* config first, command-line argument config second: ```csharp @@ -572,8 +393,7 @@ public class Program { app.Run(context => context.Response.WriteAsync("Hello, World!")); - }) - .Build(); + }); } } ``` @@ -586,49 +406,6 @@ public class Program } ``` -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -Overriding the configuration provided by `UseUrls` with *hostsettings.json* config first, command-line argument config second: - -```csharp -public class Program -{ - public static void Main(string[] args) - { - var config = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("hostsettings.json", optional: true) - .AddCommandLine(args) - .Build(); - - var host = new WebHostBuilder() - .UseUrls("http://*:5000") - .UseConfiguration(config) - .UseKestrel() - .Configure(app => - { - app.Run(context => - context.Response.WriteAsync("Hello, World!")); - }) - .Build(); - - host.Run(); - } -} -``` - -*hostsettings.json*: - -```json -{ - urls: "http://*:5005" -} -``` - -::: moniker-end - > [!NOTE] > The [UseConfiguration](/dotnet/api/microsoft.aspnetcore.hosting.hostingabstractionswebhostbuilderextensions.useconfiguration) extension method isn't currently capable of parsing a configuration section returned by `GetSection` (for example, `.UseConfiguration(Configuration.GetSection("section"))`. The `GetSection` method filters the configuration keys to the section requested but leaves the section name on the keys (for example, `section:urls`, `section:environment`). The `UseConfiguration` method expects the keys to match the `WebHostBuilder` keys (for example, `urls`, `environment`). The presence of the section name on the keys prevents the section's values from configuring the host. This issue will be addressed in an upcoming release. For more information and workarounds, see [Passing configuration section into WebHostBuilder.UseConfiguration uses full keys](https://github.com/aspnet/Hosting/issues/839). > @@ -642,8 +419,6 @@ dotnet run --urls "http://*:8080" ## Manage the host -::: moniker range=">= aspnetcore-2.0" - **Run** The `Run` method starts the web app and blocks the calling thread until the host is shut down: @@ -813,52 +588,6 @@ using (var host = WebHost.StartWith("http://localhost:8080", app => Produces the same result as **StartWith(Action<IApplicationBuilder> app)**, except the app responds on `http://localhost:8080`. -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -**Run** - -The `Run` method starts the web app and blocks the calling thread until the host is shut down: - -```csharp -host.Run(); -``` - -**Start** - -Run the host in a non-blocking manner by calling its `Start` method: - -```csharp -using (host) -{ - host.Start(); - Console.ReadLine(); -} -``` - -If a list of URLs is passed to the `Start` method, it listens on the URLs specified: - -```csharp -var urls = new List() -{ - "http://*:5000", - "http://localhost:5001" -}; - -var host = new WebHostBuilder() - .UseKestrel() - .UseStartup() - .Start(urls.ToArray()); - -using (host) -{ - Console.ReadLine(); -} -``` - -::: moniker-end - ## IHostingEnvironment interface The [IHostingEnvironment interface](/dotnet/api/microsoft.aspnetcore.hosting.ihostingenvironment) provides information about the app's web hosting environment. Use [constructor injection](xref:fundamentals/dependency-injection) to obtain the `IHostingEnvironment` in order to use its properties and extension methods: @@ -1015,12 +744,8 @@ public class MyClass ## Scope validation -::: moniker range=">= aspnetcore-2.0" - [CreateDefaultBuilder](/dotnet/api/microsoft.aspnetcore.webhost.createdefaultbuilder) sets [ServiceProviderOptions.ValidateScopes](/dotnet/api/microsoft.extensions.dependencyinjection.serviceprovideroptions.validatescopes) to `true` if the app's environment is Development. -::: moniker-end - When `ValidateScopes` is set to `true`, the default service provider performs checks to verify that: * Scoped services aren't directly or indirectly resolved from the root service provider. @@ -1039,42 +764,6 @@ WebHost.CreateDefaultBuilder(args) }) ``` -::: moniker range="= aspnetcore-2.0" - -## Troubleshooting System.ArgumentException - -**The following only applies to ASP.NET Core 2.0 apps when the app doesn't call `UseStartup` or `Configure`.** - -A host may be built by injecting `IStartup` directly into the dependency injection container rather than calling `UseStartup` or `Configure`: - -```csharp -services.AddSingleton(); -``` - -If the host is built this way, the following error may occur: - -``` -Unhandled Exception: System.ArgumentException: A valid non-empty application name must be provided. -``` - -This occurs because the app name (the name of the current assembly) is required to scan for `HostingStartupAttributes`. If the app manually injects `IStartup` into the dependency injection container, add the following call to `WebHostBuilder` with the assembly name specified: - -```csharp -WebHost.CreateDefaultBuilder(args) - .UseSetting("applicationName", "AssemblyName") -``` - -Alternatively, add a dummy `Configure` to the `WebHostBuilder`, which sets the app name automatically: - -```csharp -WebHost.CreateDefaultBuilder(args) - .Configure(_ => { }) -``` - -For more information, see [Announcements: Microsoft.Extensions.PlatformAbstractions has been removed (comment)](https://github.com/aspnet/Announcements/issues/237#issuecomment-323786938) and the [StartupInjection sample](https://github.com/aspnet/Hosting/blob/8377d226f1e6e1a97dabdb6769a845eeccc829ed/samples/SampleStartups/StartupInjection.cs). - -::: moniker-end - ## Additional resources * diff --git a/aspnetcore/fundamentals/servers/aspnet-core-module.md b/aspnetcore/fundamentals/servers/aspnet-core-module.md index aada9fc91672..c1d0412865c0 100644 --- a/aspnetcore/fundamentals/servers/aspnet-core-module.md +++ b/aspnetcore/fundamentals/servers/aspnet-core-module.md @@ -1,6 +1,6 @@ --- title: ASP.NET Core Module -author: rick-anderson +author: guardrex description: Learn how the ASP.NET Core Module allows the Kestrel web server to use IIS or IIS Express as a reverse proxy server. ms.author: tdykstra ms.custom: mvc diff --git a/aspnetcore/fundamentals/servers/index.md b/aspnetcore/fundamentals/servers/index.md index 6324bca9d416..f93482bcb4f2 100644 --- a/aspnetcore/fundamentals/servers/index.md +++ b/aspnetcore/fundamentals/servers/index.md @@ -1,6 +1,6 @@ --- title: Web server implementations in ASP.NET Core -author: rick-anderson +author: guardrex description: Discover the web servers Kestrel and HTTP.sys for ASP.NET Core. Learn how to choose a server and when to use a reverse proxy server. ms.author: tdykstra ms.custom: mvc diff --git a/aspnetcore/fundamentals/servers/kestrel.md b/aspnetcore/fundamentals/servers/kestrel.md index aa27c43808ff..09644c7faa53 100644 --- a/aspnetcore/fundamentals/servers/kestrel.md +++ b/aspnetcore/fundamentals/servers/kestrel.md @@ -1,16 +1,19 @@ --- title: Kestrel web server implementation in ASP.NET Core -author: rick-anderson +author: guardrex description: Learn about Kestrel, the cross-platform web server for ASP.NET Core. +monikerRange: '>= aspnetcore-2.1' ms.author: tdykstra ms.custom: mvc -ms.date: 09/13/2018 +ms.date: 11/05/2018 uid: fundamentals/servers/kestrel --- # Kestrel web server implementation in ASP.NET Core By [Tom Dykstra](https://github.com/tdykstra), [Chris Ross](https://github.com/Tratcher), and [Stephen Halter](https://twitter.com/halter73) +For the 1.1 version of this topic, download [Kestrel web server implementation in ASP.NET Core (version 1.1, PDF)](https://webpifeed.blob.core.windows.net/webpifeed/Partners/Kestrel_1.1.pdf). + Kestrel is a cross-platform [web server for ASP.NET Core](xref:fundamentals/servers/index). Kestrel is the web server that's included by default in ASP.NET Core project templates. Kestrel supports the following features: @@ -61,8 +64,6 @@ HTTP/2 is disabled by default. For more information on configuration, see the [K ## When to use Kestrel with a reverse proxy -::: moniker range=">= aspnetcore-2.0" - You can use Kestrel by itself or with a *reverse proxy server*, such as IIS, Nginx, or Apache. A reverse proxy server receives HTTP requests from the Internet and forwards them to Kestrel after some preliminary handling. ![Kestrel communicates directly with the Internet without a reverse proxy server](kestrel/_static/kestrel-to-internet2.png) @@ -71,22 +72,6 @@ You can use Kestrel by itself or with a *reverse proxy server*, such as IIS, Ngi Either configuration—with or without a reverse proxy server—is a valid and supported hosting configuration for ASP.NET Core 2.0 or later apps. -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -If an app accepts requests only from an internal network, Kestrel can be used directly as the app's server. - -![Kestrel communicates directly with your internal network](kestrel/_static/kestrel-to-internal.png) - -If you expose your app to the Internet, use IIS, Nginx, or Apache as a *reverse proxy server*. A reverse proxy server receives HTTP requests from the Internet and forwards them to Kestrel after some preliminary handling. - -![Kestrel communicates indirectly with the Internet through a reverse proxy server, such as IIS, Nginx, or Apache](kestrel/_static/kestrel-to-internet.png) - -A reverse proxy is required for public-facing edge server deployments (exposed to traffic from the Internet) for security reasons. The 1.x versions of Kestrel don't have a full complement of defenses against attacks, such as appropriate timeouts, size limits, and concurrent connection limits. - -::: moniker-end - A reverse proxy scenario exists when there are multiple apps that share the same IP and port running on a single server. Kestrel doesn't support this scenario because Kestrel doesn't support sharing the same IP and port among multiple processes. When Kestrel is configured to listen on a port, Kestrel handles all of the traffic for that port regardless of requests' host header. A reverse proxy that can share ports has the ability to forward requests to Kestrel on a unique IP and port. Even if a reverse proxy server isn't required, using a reverse proxy server might be a good choice: @@ -101,16 +86,12 @@ Even if a reverse proxy server isn't required, using a reverse proxy server migh ## How to use Kestrel in ASP.NET Core apps -::: moniker range=">= aspnetcore-2.0" - The [Microsoft.AspNetCore.Server.Kestrel](https://www.nuget.org/packages/Microsoft.AspNetCore.Server.Kestrel/) package is included in the [Microsoft.AspNetCore.App metapackage](xref:fundamentals/metapackage-app) (ASP.NET Core 2.1 or later). ASP.NET Core project templates use Kestrel by default. In *Program.cs*, the template code calls [CreateDefaultBuilder](/dotnet/api/microsoft.aspnetcore.webhost.createdefaultbuilder), which calls [UseKestrel](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilderkestrelextensions.usekestrel) behind the scenes. [!code-csharp[](kestrel/samples/2.x/KestrelSample/Program.cs?name=snippet_DefaultBuilder&highlight=7)] -::: moniker-end - ::: moniker range=">= aspnetcore-2.2" To provide additional configuration after calling `CreateDefaultBuilder`, use `ConfigureKestrel`: @@ -127,37 +108,24 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) => ::: moniker-end -::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1" +::: moniker range="< aspnetcore-2.2" To provide additional configuration after calling `CreateDefaultBuilder`, call [UseKestrel](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilderkestrelextensions.usekestrel): ```csharp -public static IWebHost BuildWebHost(string[] args) => +public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() .UseKestrel(options => { // Set properties and call methods on options - }) - .Build(); + }); ``` ::: moniker-end -::: moniker range="< aspnetcore-2.0" - -Install the [Microsoft.AspNetCore.Server.Kestrel](https://www.nuget.org/packages/Microsoft.AspNetCore.Server.Kestrel/) NuGet package. - -Call the [UseKestrel](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilderkestrelextensions.usekestrel?view=aspnetcore-1.1) extension method on [WebHostBuilder](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilder?view=aspnetcore-1.1) in the `Main` method, specifying any [Kestrel options](/dotnet/api/microsoft.aspnetcore.server.kestrel.kestrelserveroptions?view=aspnetcore-1.1) required, as shown in the next section. - -[!code-csharp[](kestrel/samples/1.x/KestrelSample/Program.cs?name=snippet_Main&highlight=13-19)] - -::: moniker-end - ## Kestrel options -::: moniker range=">= aspnetcore-2.0" - The Kestrel web server has constraint configuration options that are especially useful in Internet-facing deployments. A few important limits that can be customized: * Maximum client connections @@ -171,8 +139,6 @@ Set these and other constraints on the [Limits](/dotnet/api/microsoft.aspnetcore [MaxConcurrentConnections](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserverlimits.maxconcurrentconnections) [MaxConcurrentUpgradedConnections](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserverlimits.maxconcurrentupgradedconnections) -::: moniker-end - The maximum number of concurrent open TCP connections can be set for the entire app with the following code: ::: moniker range=">= aspnetcore-2.2" @@ -181,7 +147,7 @@ The maximum number of concurrent open TCP connections can be set for the entire ::: moniker-end -::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1" +::: moniker range="< aspnetcore-2.2" ```csharp public static IWebHostBuilder CreateWebHostBuilder(string[] args) => @@ -203,7 +169,7 @@ There's a separate limit for connections that have been upgraded from HTTP or HT ::: moniker-end -::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1" +::: moniker range="< aspnetcore-2.2" ```csharp public static IWebHostBuilder CreateWebHostBuilder(string[] args) => @@ -217,8 +183,6 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) => ::: moniker-end -::: moniker range=">= aspnetcore-2.0" - The maximum number of connections is unlimited (null) by default. ### Maximum request body size @@ -234,8 +198,6 @@ The recommended approach to override the limit in an ASP.NET Core MVC app is to public IActionResult MyActionMethod() ``` -::: moniker-end - Here's an example that shows how to configure the constraint for the app on every request: ::: moniker range=">= aspnetcore-2.2" @@ -244,7 +206,7 @@ Here's an example that shows how to configure the constraint for the app on ever ::: moniker-end -::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1" +::: moniker range="< aspnetcore-2.2" ```csharp public static IWebHostBuilder CreateWebHostBuilder(string[] args) => @@ -262,8 +224,6 @@ You can override the setting on a specific request in middleware: ::: moniker-end -::: moniker range=">= aspnetcore-2.0" - An exception is thrown if you attempt to configure the limit on a request after the app has started to read the request. There's an `IsReadOnly` property that indicates if the `MaxRequestBodySize` property is in read-only state, meaning it's too late to configure the limit. ### Minimum request body data rate @@ -279,15 +239,13 @@ A minimum rate also applies to the response. The code to set the request limit a Here's an example that shows how to configure the minimum data rates in *Program.cs*: -::: moniker-end - ::: 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" +::: moniker range="< aspnetcore-2.2" ```csharp public static IWebHostBuilder CreateWebHostBuilder(string[] args) => @@ -302,10 +260,6 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) => }); ``` -You can configure the rates per request in middleware: - -[!code-csharp[](kestrel/samples/2.x/KestrelSample/Startup.cs?name=snippet_Limits&highlight=5-8)] - ::: moniker-end ::: moniker range=">= aspnetcore-2.2" @@ -360,51 +314,14 @@ The default value is 2^14 (16,384). ::: moniker-end -::: moniker range=">= aspnetcore-2.0" - For information about other Kestrel options and limits, see: * [KestrelServerOptions](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserveroptions) * [KestrelServerLimits](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserverlimits) * [ListenOptions](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.listenoptions) -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -For information about Kestrel options and limits, see: - -* [KestrelServerOptions class](/dotnet/api/microsoft.aspnetcore.server.kestrel.kestrelserveroptions?view=aspnetcore-1.1) -* [KestrelServerLimits](/dotnet/api/microsoft.aspnetcore.server.kestrel.kestrelserverlimits?view=aspnetcore-1.1) - -::: moniker-end - ## Endpoint configuration -::: moniker range="= aspnetcore-2.0" - -By default, ASP.NET Core binds to `http://localhost:5000`. Call [Listen](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserveroptions.listen) or [ListenUnixSocket](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserveroptions.listenunixsocket) methods on [KestrelServerOptions](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserveroptions) to configure URL prefixes and ports for Kestrel. `UseUrls`, the `--urls` command-line argument, `urls` host configuration key, and the `ASPNETCORE_URLS` environment variable also work but have the limitations noted later in this section. - -The `urls` host configuration key must come from the host configuration, not the app configuration. Adding a `urls` key and value to *appsettings.json* doesn't affect host configuration because the host is completely initialized by the time the configuration is read from the configuration file. However, a `urls` key in *appsettings.json* can be used with [UseConfiguration](/dotnet/api/microsoft.aspnetcore.hosting.hostingabstractionswebhostbuilderextensions.useconfiguration) on the host builder to configure the host: - -```csharp -var config = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appSettings.json", optional: true, reloadOnChange: true) - .Build(); - -var host = new WebHostBuilder() - .UseKestrel() - .UseConfiguration(config) - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseStartup() - .Build(); -``` - -::: moniker-end - -::: moniker range=">= aspnetcore-2.1" - By default, ASP.NET Core binds to: * `http://localhost:5000` @@ -608,8 +525,6 @@ SNI support requires: * Running on target framework `netcoreapp2.1`. On `netcoreapp2.0` and `net461`, the callback is invoked but the `name` is always `null`. The `name` is also `null` if the client doesn't provide the host name parameter in the TLS handshake. * All websites run on the same Kestrel instance. Kestrel doesn't support sharing an IP address and port across multiple instances without a reverse proxy. -::: moniker-end - ::: moniker range=">= aspnetcore-2.2" ```csharp @@ -653,10 +568,10 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) => ::: moniker-end -::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1" +::: moniker range="< aspnetcore-2.2" ```csharp -public static IWebHost BuildWebHost(string[] args) => +public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() .UseKestrel((context, options) => @@ -707,7 +622,7 @@ The [Listen](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelservero ::: moniker-end -::: moniker range="= aspnetcore-2.0 || aspnetcore-2.1" +::: moniker range="< aspnetcore-2.2" ```csharp public static void Main(string[] args) @@ -728,9 +643,26 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) => }); ``` -::: moniker-end +```csharp +public static void Main(string[] args) +{ + CreateWebHostBuilder(args).Build().Run(); +} + +public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup() + .UseKestrel(options => + { + options.Listen(IPAddress.Loopback, 5000); + options.Listen(IPAddress.Loopback, 5001, listenOptions => + { + listenOptions.UseHttps("testCert.pfx", "testPassword"); + }); + }); +``` -::: moniker range=">= aspnetcore-2.0" +::: moniker-end 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. @@ -740,15 +672,13 @@ The example configures SSL for an endpoint with [ListenOptions](/dotnet/api/micr Listen on a Unix socket with [ListenUnixSocket](/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserveroptions.listenunixsocket) for improved performance with Nginx, as shown in this example: -::: moniker-end - ::: 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" +::: moniker range="< aspnetcore-2.2" ```csharp public static IWebHostBuilder CreateWebHostBuilder(string[] args) => @@ -766,8 +696,6 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) => ::: moniker-end -::: moniker range=">= aspnetcore-2.0" - ### Port 0 When the port number `0` is specified, Kestrel dynamically binds to an available port. The following example shows how to determine which port Kestrel actually bound at runtime: @@ -798,25 +726,6 @@ These methods are useful for making code work with servers other than Kestrel. H When using IIS, the URL bindings for IIS override bindings are set by either `Listen` or `UseUrls`. For more information, see the [ASP.NET Core Module](xref:fundamentals/servers/aspnet-core-module) topic. -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -By default, ASP.NET Core binds to `http://localhost:5000`. Configure URL prefixes and ports for Kestrel using: - -* [UseUrls](/dotnet/api/microsoft.aspnetcore.hosting.hostingabstractionswebhostbuilderextensions.useurls?view=aspnetcore-1.1) extension method -* `--urls` command-line argument -* `urls` host configuration key -* ASP.NET Core configuration system, including `ASPNETCORE_URLS` environment variable - -For more information on these methods, see [Hosting](xref:fundamentals/host/index). - -### IIS endpoint configuration - -When using IIS, the URL bindings for IIS override bindings set by `UseUrls`. For more information, see the [ASP.NET Core Module](xref:fundamentals/servers/aspnet-core-module) topic. - -::: moniker-end - ::: moniker range=">= aspnetcore-2.2" ### ListenOptions.Protocols @@ -856,7 +765,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) => listenOptions.Protocols = HttpProtocols.Http1AndHttp2; listenOptions.UseHttps("testCert.pfx", "testPassword"); }); - } + }); ``` Optionally create an `IConnectionAdapter` implementation to filter TLS handshakes on a per-connection basis for specific ciphers: @@ -873,7 +782,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) => listenOptions.UseHttps("testCert.pfx", "testPassword"); listenOptions.ConnectionAdapters.Add(new TlsFilterAdapter()); }); - } + }); ``` ```csharp @@ -952,8 +861,6 @@ Protocols specified in code override values set by configuration. ::: moniker-end -::: moniker range=">= aspnetcore-2.1" - ## Transport configuration With the release of ASP.NET Core 2.1, Kestrel's default transport is no longer based on Libuv but instead based on managed sockets. This is a breaking change for ASP.NET Core 2.0 apps upgrading to 2.1 that call [WebHostBuilderLibuvExtensions.UseLibuv](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilderlibuvextensions.uselibuv) and depend on either of the following packages: @@ -987,14 +894,10 @@ For ASP.NET Core 2.1 or later projects that use the [Microsoft.AspNetCore.App me } ``` -::: moniker-end - ### URL prefixes When using `UseUrls`, `--urls` command-line argument, `urls` host configuration key, or `ASPNETCORE_URLS` environment variable, the URL prefixes can be in any of the following formats. -::: moniker range=">= aspnetcore-2.0" - Only HTTP URL prefixes are valid. Kestrel doesn't support SSL when configuring URL bindings using `UseUrls`. * IPv4 address with port number @@ -1035,252 +938,16 @@ Only HTTP URL prefixes are valid. Kestrel doesn't support SSL when configuring U When `localhost` is specified, Kestrel attempts to bind to both IPv4 and IPv6 loopback interfaces. If the requested port is in use by another service on either loopback interface, Kestrel fails to start. If either loopback interface is unavailable for any other reason (most commonly because IPv6 isn't supported), Kestrel logs a warning. -::: moniker-end - -::: moniker range="< aspnetcore-2.0" - -* IPv4 address with port number - - ``` - http://65.55.39.10:80/ - https://65.55.39.10:443/ - ``` - - `0.0.0.0` is a special case that binds to all IPv4 addresses. - -* IPv6 address with port number - - ``` - http://[0:0:0:0:0:ffff:4137:270a]:80/ - https://[0:0:0:0:0:ffff:4137:270a]:443/ - ``` - - `[::]` is the IPv6 equivalent of IPv4 `0.0.0.0`. - -* Host name with port number - - ``` - http://contoso.com:80/ - http://*:80/ - https://contoso.com:443/ - https://*:443/ - ``` - - Host names, `*`, and `+` aren't special. Anything that isn't a recognized IP address or `localhost` binds to all IPv4 and IPv6 IPs. To bind different host names to different ASP.NET Core apps on the same port, use [WebListener](xref:fundamentals/servers/weblistener) or a reverse proxy server, such as IIS, Nginx, or Apache. - -* Host `localhost` name with port number or loopback IP with port number - - ``` - http://localhost:5000/ - http://127.0.0.1:5000/ - http://[::1]:5000/ - ``` - - When `localhost` is specified, Kestrel attempts to bind to both IPv4 and IPv6 loopback interfaces. If the requested port is in use by another service on either loopback interface, Kestrel fails to start. If either loopback interface is unavailable for any other reason (most commonly because IPv6 isn't supported), Kestrel logs a warning. - -* Unix socket - - ``` - http://unix:/run/dan-live.sock - ``` - -**Port 0** - -When the port number is `0` is specified, Kestrel dynamically binds to an available port. Binding to port `0` is allowed for any host name or IP except for `localhost`. - -When the app is run, the console window output indicates the dynamic port where the app can be reached: - -```console -Now listening on: http://127.0.0.1:48508 -``` - -**URL prefixes for SSL** - -If calling the `UseHttps` extension method, be sure to include URL prefixes with `https:`: - -```csharp -var host = new WebHostBuilder() - .UseKestrel(options => - { - options.UseHttps("testCert.pfx", "testPassword"); - }) - .UseUrls("http://localhost:5000", "https://localhost:5001") - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseStartup() - .Build(); -``` - -> [!NOTE] -> HTTPS and HTTP can't be hosted on the same port. - -[!INCLUDE [How to make an X.509 cert](~/includes/make-x509-cert.md)] - -::: moniker-end - ## Host filtering While Kestrel supports configuration based on prefixes such as `http://example.com:5000`, Kestrel largely ignores the host name. Host `localhost` is a special case used for binding to loopback addresses. Any host other than an explicit IP address binds to all public IP addresses. None of this information is used to validate request `Host` headers. -::: moniker range="< aspnetcore-2.0" - -As a workaround, host behind a reverse proxy with host header filtering. This is the only supported scenario for Kestrel in ASP.NET Core 1.x. - -::: moniker-end - -::: moniker range="= aspnetcore-2.0" - -As a workaround, use middleware to filter requests by the `Host` header: - -```csharp -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Primitives; -using Microsoft.Net.Http.Headers; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -// A normal middleware would provide an options type, config binding, extension methods, etc.. -// This intentionally does all of the work inside of the middleware so it can be -// easily copy-pasted into docs and other projects. -public class HostFilteringMiddleware -{ - private readonly RequestDelegate _next; - private readonly IList _hosts; - private readonly ILogger _logger; - - public HostFilteringMiddleware(RequestDelegate next, IConfiguration config, ILogger logger) - { - if (config == null) - { - throw new ArgumentNullException(nameof(config)); - } - - _next = next ?? throw new ArgumentNullException(nameof(next)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - - // A semicolon separated list of host names without the port numbers. - // IPv6 addresses must use the bounding brackets and be in their normalized form. - _hosts = config["AllowedHosts"]?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); - if (_hosts == null || _hosts.Count == 0) - { - throw new InvalidOperationException("No configuration entry found for AllowedHosts."); - } - } - - public Task Invoke(HttpContext context) - { - if (!ValidateHost(context)) - { - context.Response.StatusCode = 400; - _logger.LogDebug("Request rejected due to incorrect Host header."); - return Task.CompletedTask; - } - - return _next(context); - } - - // This does not duplicate format validations that are expected to be performed by the host. - private bool ValidateHost(HttpContext context) - { - StringSegment host = context.Request.Headers[HeaderNames.Host].ToString().Trim(); - - if (StringSegment.IsNullOrEmpty(host)) - { - // Http/1.0 does not require the Host header. - // Http/1.1 requires the header but the value may be empty. - return true; - } - - // Drop the port - - var colonIndex = host.LastIndexOf(':'); - - // IPv6 special case - if (host.StartsWith("[", StringComparison.Ordinal)) - { - var endBracketIndex = host.IndexOf(']'); - if (endBracketIndex < 0) - { - // Invalid format - return false; - } - if (colonIndex < endBracketIndex) - { - // No port, just the IPv6 Host - colonIndex = -1; - } - } - - if (colonIndex > 0) - { - host = host.Subsegment(0, colonIndex); - } - - foreach (var allowedHost in _hosts) - { - if (StringSegment.Equals(allowedHost, host, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - // Sub-domain wildcards: *.example.com - if (allowedHost.StartsWith("*.", StringComparison.Ordinal) && host.Length >= allowedHost.Length) - { - // .example.com - var allowedRoot = new StringSegment(allowedHost, 1, allowedHost.Length - 1); - - var hostRoot = host.Subsegment(host.Length - allowedRoot.Length, allowedRoot.Length); - if (hostRoot.Equals(allowedRoot, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - } - } - - return false; - } -} -``` - -Register the preceding `HostFilteringMiddleware` in `Startup.Configure`. Note that the [ordering of middleware registration](xref:fundamentals/middleware/index#order) is important. Registration should occur immediately after Diagnostic Middleware registration (for example, `app.UseExceptionHandler`). - -```csharp -public void Configure(IApplicationBuilder app, IHostingEnvironment env) -{ - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseBrowserLink(); - } - else - { - app.UseExceptionHandler("/Home/Error"); - } - - app.UseMiddleware(); - - app.UseMvcWithDefaultRoute(); -} -``` - -The middleware expects an `AllowedHosts` key in *appsettings.json*/*appsettings.\.json*. The value is a semicolon-delimited list of host names without port numbers: - -::: moniker-end - -::: moniker range=">= aspnetcore-2.1" - As a workaround, use Host Filtering Middleware. Host Filtering Middleware is provided by the [Microsoft.AspNetCore.HostFiltering](https://www.nuget.org/packages/Microsoft.AspNetCore.HostFiltering) package, which is included in the [Microsoft.AspNetCore.App metapackage](xref:fundamentals/metapackage-app) (ASP.NET Core 2.1 or later). The middleware is added by [CreateDefaultBuilder](/dotnet/api/microsoft.aspnetcore.webhost.createdefaultbuilder), which calls [AddHostFiltering](/dotnet/api/microsoft.aspnetcore.builder.hostfilteringservicesextensions.addhostfiltering): [!code-csharp[](kestrel/samples-snapshot/2.x/KestrelSample/Program.cs?name=snippet_Program&highlight=9)] Host Filtering Middleware is disabled by default. To enable the middleware, define an `AllowedHosts` key in *appsettings.json*/*appsettings.\.json*. The value is a semicolon-delimited list of host names without port numbers: -::: moniker-end - -::: moniker range=">= aspnetcore-2.0" - *appsettings.json*: ```json @@ -1294,8 +961,6 @@ Host Filtering Middleware is disabled by default. To enable the middleware, defi > > For more information on Forwarded Headers Middleware, see [Configure ASP.NET Core to work with proxy servers and load balancers](xref:host-and-deploy/proxy-load-balancer). -::: moniker-end - ## Additional resources * [Enforce HTTPS](xref:security/enforcing-ssl) diff --git a/aspnetcore/fundamentals/servers/weblistener.md b/aspnetcore/fundamentals/servers/weblistener.md index df57ab734df1..6235269e7a40 100644 --- a/aspnetcore/fundamentals/servers/weblistener.md +++ b/aspnetcore/fundamentals/servers/weblistener.md @@ -1,6 +1,6 @@ --- title: WebListener web server implementation in ASP.NET Core -author: rick-anderson +author: guardrex description: Learn about WebListener, a web server for ASP.NET Core on Windows that can be used for direct connection to the Internet without IIS. monikerRange: '< aspnetcore-2.0' ms.author: riande diff --git a/aspnetcore/host-and-deploy/iis/index.md b/aspnetcore/host-and-deploy/iis/index.md index 138a74bf8b0a..6d1c1fc4f945 100644 --- a/aspnetcore/host-and-deploy/iis/index.md +++ b/aspnetcore/host-and-deploy/iis/index.md @@ -4,14 +4,14 @@ author: guardrex description: Learn how to host ASP.NET Core apps on Windows Server Internet Information Services (IIS). ms.author: riande ms.custom: mvc -ms.date: 09/21/2018 +ms.date: 11/05/2018 uid: host-and-deploy/iis/index --- # Host ASP.NET Core on Windows with IIS By [Luke Latham](https://github.com/guardrex) -[Install the .NET Core Hosting Bundle](#install-the-NET-core-hosting-bundle) +[Install the .NET Core Hosting Bundle](#install-the-net-core-hosting-bundle) ## Supported operating systems @@ -76,7 +76,7 @@ A typical *Program.cs* calls to begin setting up a host. For out-of-process hosting with IIS, `CreateDefaultBuilder` configures [Kestrel](xref:fundamentals/servers/kestrel) as the web server and enables IIS integration by configuring the base path and port for the [ASP.NET Core Module](xref:fundamentals/servers/aspnet-core-module): ```csharp -public static IWebHost BuildWebHost(string[] args) => +public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) ... ``` @@ -98,7 +98,7 @@ For more information on the in-process and out-of-process hosting models, see th A typical *Program.cs* calls to begin setting up a host. `CreateDefaultBuilder` configures [Kestrel](xref:fundamentals/servers/kestrel) as the web server and enables IIS integration by configuring the base path and port for the [ASP.NET Core Module](xref:fundamentals/servers/aspnet-core-module): ```csharp -public static IWebHost BuildWebHost(string[] args) => +public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) ... ``` diff --git a/aspnetcore/tutorials/getting-started-with-swashbuckle.md b/aspnetcore/tutorials/getting-started-with-swashbuckle.md index a6a5f77cec89..7167fb753599 100644 --- a/aspnetcore/tutorials/getting-started-with-swashbuckle.md +++ b/aspnetcore/tutorials/getting-started-with-swashbuckle.md @@ -4,7 +4,7 @@ author: zuckerthoben description: Learn how to add Swashbuckle to your ASP.NET Core web API project to integrate the Swagger UI. ms.author: scaddie ms.custom: mvc -ms.date: 08/20/2018 +ms.date: 11/05/2018 uid: tutorials/get-started-with-swashbuckle --- # Get started with Swashbuckle and ASP.NET Core @@ -120,7 +120,7 @@ The Swagger UI displays the version's information: XML comments can be enabled with the following approaches: -# [Visual Studio](#tab/visual-studio-xml/) +#### [Visual Studio](#tab/visual-studio) ::: moniker range=">= aspnetcore-2.0" @@ -138,7 +138,7 @@ XML comments can be enabled with the following approaches: ::: moniker-end -# [Visual Studio for Mac](#tab/visual-studio-mac-xml/) +#### [Visual Studio for Mac](#tab/visual-studio-mac) ::: moniker range=">= aspnetcore-2.0" @@ -156,7 +156,23 @@ XML comments can be enabled with the following approaches: ::: moniker-end -# [Visual Studio Code](#tab/visual-studio-code-xml/) +#### [Visual Studio Code](#tab/visual-studio-code) + +Manually add the highlighted lines to the *.csproj* file: + +::: moniker range=">= aspnetcore-2.0" + +[!code-xml[](../tutorials/web-api-help-pages-using-swagger/samples/2.1/TodoApi.Swashbuckle/TodoApi.csproj?name=snippet_SuppressWarnings&highlight=1-2,4)] + +::: moniker-end + +::: moniker range="<= aspnetcore-1.1" + +[!code-xml[](../tutorials/web-api-help-pages-using-swagger/samples/2.0/TodoApi.Swashbuckle/TodoApi.csproj?name=snippet_SuppressWarnings&highlight=1-2,4)] + +::: moniker-end + +#### [.NET Core CLI](#tab/netcore-cli) Manually add the highlighted lines to the *.csproj* file: