Use ASP.NET Core with HTTP/2 on IIS
HTTP/2 is supported with ASP.NET Core in the following IIS deployment scenarios:
- Windows Server 2016 or later / Windows 10 or later
- IIS 10 or later
- TLS 1.2 or later connection
- When hosting out-of-process: Public-facing edge server connections use HTTP/2, but the reverse proxy connection to the Kestrel server uses HTTP/1.1.
For an in-process deployment when an HTTP/2 connection is established, HttpRequest.Protocol reports HTTP/2. For an out-of-process deployment when an HTTP/2 connection is established, HttpRequest.Protocol reports HTTP/1.1.
For more information on the in-process and out-of-process hosting models, see ASP.NET Core Module.
HTTP/2 is enabled by default for HTTPS/TLS connections. Connections fall back to HTTP/1.1 if an HTTP/2 connection isn't established. For more information on HTTP/2 configuration with IIS deployments, see HTTP/2 on IIS.
Advanced HTTP/2 features to support gRPC
Additional HTTP/2 features in IIS support gRPC, including support for response trailers and sending reset frames.
Requirements to run gRPC on IIS:
- In-process hosting.
- Windows 10, OS Build 20300.1000 or later. May require use of a Windows Insider build.
- TLS 1.2 or later connection
Trailers
HTTP Trailers are similar to HTTP Headers, except they are sent after the response body is sent. For IIS and HTTP.sys, only HTTP/2 response trailers are supported.
if (httpContext.Response.SupportsTrailers())
{
httpContext.Response.DeclareTrailer("trailername");
// Write body
httpContext.Response.WriteAsync("Hello world");
httpContext.Response.AppendTrailer("trailername", "TrailerValue");
}
In the preceding example code:
SupportsTrailersensures that trailers are supported for the response.DeclareTraileradds the given trailer name to theTrailerresponse header. Declaring a response's trailers is optional, but recommended. IfDeclareTraileris called, it must be before the response headers are sent.AppendTrailerappends the trailer.
Reset
Reset allows for the server to reset a HTTP/2 request with a specified error code. A reset request is considered aborted.
var resetFeature = httpContext.Features.Get<IHttpResetFeature>();
resetFeature.Reset(errorCode: 2);
Reset in the preceding code example specifies the INTERNAL_ERROR error code. For more information about HTTP/2 error codes, visit the HTTP/2 specification error code section.