AspNetCore.Docs/aspnetcore/fundamentals/servers/httpsys.md

11 KiB

title author description keywords ms.author manager ms.date ms.topic ms.assetid ms.technology ms.prod uid
HTTP.sys web server implementation in ASP.NET Core rick-anderson Introduces HTTP.sys, a web server for ASP.NET Core on Windows. Built on the Http.Sys kernel mode driver, HTTP.sys is an alternative to Kestrel that can be used for direct connection to the Internet without IIS. ASP.NET Core,HttpSys,HTTP.sys,HttpListener,url prefixes,SSL riande wpickett 08/07/2017 article 0a7286e4-6428-424e-b5c4-5c98815cf61c aspnet asp.net-core fundamentals/servers/httpsys

HTTP.sys web server implementation in ASP.NET Core

By Tom Dykstra and Chris Ross

[!NOTE] This topic applies only to ASP.NET Core 2.0 and later. In earlier versions of ASP.NET Core, HTTP.sys is named WebListener.

HTTP.sys is a web server for ASP.NET Core that runs only on Windows. It's built on the Http.Sys kernel mode driver. HTTP.sys is an alternative to Kestrel that offers some features that Kestel doesn't. HTTP.sys can't be used with IIS or IIS Express, as it isn't compatible with the ASP.NET Core Module.

HTTP.sys supports the following features:

  • Windows Authentication
  • Port sharing
  • HTTPS with SNI
  • HTTP/2 over TLS (Windows 10)
  • Direct file transmission
  • Response caching
  • WebSockets (Windows 8)

Supported Windows versions:

  • Windows 7 and Windows Server 2008 R2 and later

View or download sample code (how to download)

When to use HTTP.sys

HTTP.sys is useful for deployments where you need to expose the server directly to the Internet without using IIS.

HTTP.sys communicates directly with the Internet

Because it's built on Http.Sys, HTTP.sys doesn't require a reverse proxy server for protection against attacks. Http.Sys is mature technology that protects against many kinds of attacks and provides the robustness, security, and scalability of a full-featured web server. IIS itself runs as an HTTP listener on top of Http.Sys.

HTTP.sys is a good choice for internal deployments when you need a feature not available in Kestrel, such as Windows authentication.

HTTP.sys communicates directly with your internal network

How to use HTTP.sys

Here's an overview of setup tasks for the host OS and your ASP.NET Core application.

Configure Windows Server

  • Install the version of .NET that your application requires, such as .NET Core or .NET Framework.

  • Preregister URL prefixes to bind to HTTP.sys, and set up SSL certificates

    If you don't preregister URL prefixes in Windows, you have to run your application with administrator privileges. The only exception is if you bind to localhost using HTTP (not HTTPS) with a port number greater than 1024; in that case, administrator privileges aren't required.

    For details, see How to preregister prefixes and configure SSL later in this article.

  • Open firewall ports to allow traffic to reach HTTP.sys.

    You can use netsh.exe or PowerShell cmdlets.

There are also Http.Sys registry settings.

Configure your ASP.NET Core application to use HTTP.sys

Configure HTTP.sys options

Here are some of the HTTP.sys settings and limits that you can configure.

Maximum client connections

The maximum number of concurrent open TCP connections can be set for the entire application with the following code in Program.cs:

[!code-csharp]

The maximum number of connections is unlimited (null) by default.

Maximum request body size

The default maximum request body size is 30,000,000 bytes, which is approximately 28.6MB.

The recommended way to override the limit in an ASP.NET Core MVC app is to use the RequestSizeLimit attribute on an action method:

[RequestSizeLimit(100000000)]
public IActionResult MyActionMethod()

Here's an example that shows how to configure the constraint for the entire application, every request:

[!code-csharp]

You can override the setting on a specific request in Startup.cs:

[!code-csharp]

An exception is thrown if you try to configure the limit on a request after the application has started reading the request. There's an IsReadOnly property that tells you if the MaxRequestBodySize property is in read-only state, meaning it's too late to configure the limit.

For information about other HTTP.sys options, see HttpSysOptions.

Configure URLs and ports to listen on

By default ASP.NET Core binds to http://localhost:5000. To configure URL prefixes and ports, you can use the UseUrls extension method, the urls command-line argument, the ASPNETCORE_URLS environment variable, or the UrlPrefixes property on HttpSysOptions. The following code example uses UrlPrefixes.

[!code-csharp]

An advantage of UrlPrefixes is that you get an error message immediately if you try to add a prefix that is formatted wrong. An advantage of UseUrls (shared with urls and ASPNETCORE_URLS) is that you can more easily switch between Kestrel and HTTP.sys.

If you use both UseUrls (or urls or ASPNETCORE_URLS) and UrlPrefixes, the settings in UrlPrefixes override the ones in UseUrls. For more information, see Hosting.

HTTP.sys uses the HTTP Server API UrlPrefix string formats.

[!NOTE] Make sure that you specify the same prefix strings in UseUrls or UrlPrefixes that you preregister on the server.

Don't use IIS

Make sure your application isn't configured to run IIS or IIS Express.

In Visual Studio, the default launch profile is for IIS Express. To run the project as a console application, manually change the selected profile, as shown in the following screen shot.

Select console app profile

Preregister URL prefixes and configure SSL

Both IIS and HTTP.sys rely on the underlying Http.Sys kernel mode driver to listen for requests and do initial processing. In IIS, the management UI gives you a relatively easy way to configure everything. However, you need to configure Http.Sys yourself. The built-in tool for doing that is netsh.exe.

With netsh.exe you can reserve URL prefixes and assign SSL certificates. The tool requires administrative privileges.

The following example shows the minimum needed to reserve URL prefixes for ports 80 and 443:

netsh http add urlacl url=http://+:80/ user=Users
netsh http add urlacl url=https://+:443/ user=Users

The following example shows how to assign an SSL certificate:

netsh http add sslcert ipport=0.0.0.0:443 certhash=MyCertHash_Here appid={00000000-0000-0000-0000-000000000000}"

Here is the reference documentation for netsh.exe:

The following resources provide detailed instructions for several scenarios. Articles that refer to HttpListener apply equally to HTTP.sys, as both are based on Http.Sys.

Here are some third-party tools that can be easier to use than the netsh.exe command line. These are not provided by or endorsed by Microsoft. The tools run as administrator by default, since netsh.exe itself requires administrator privileges.

  • http.sys Manager provides UI for listing and configuring SSL certificates and options, prefix reservations, and certificate trust lists.
  • HttpConfig lets you list or configure SSL certificates and URL prefixes. The UI is more refined than http.sys Manager and exposes a few more configuration options, but otherwise it provides similar functionality. It cannot create a new certificate trust list (CTL), but can assign existing ones.

[!INCLUDEHow to make an SSL cert]

Next steps

For more information, see the following resources: