Web server implementations in ASP.NET Core
An ASP.NET Core app runs with an in-process HTTP server implementation. The server implementation listens for HTTP requests and surfaces them to the app as sets of request features composed into an HttpContext.
ASP.NET Core ships two server implementations:
Kestrel is the web server that's included by default in ASP.NET Core new-project templates.
Kestrel can be used 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.
Either configuration — with or without a reverse proxy server — can also be used if Kestrel is only exposed to an internal network.
For information, see When to use Kestrel with a reverse proxy.
IIS, Nginx, and Apache can't be used without Kestrel or a custom server implementation. ASP.NET Core was designed to run in its own process so that it can behave consistently across platforms. IIS, Nginx, and Apache dictate their own startup procedure and environment. To use these server technologies directly, ASP.NET Core would need to adapt to the requirements of each server. Using a web server implementation, such as Kestrel, ASP.NET Core has control over the startup process and environment when hosted on different server technologies.
IIS with Kestrel
When using IIS or IIS Express as a reverse proxy for ASP.NET Core, the ASP.NET Core app runs in a process separate from the IIS worker process. In the IIS process, the ASP.NET Core Module coordinates the reverse proxy relationship. The primary functions of the ASP.NET Core Module are to start the ASP.NET Core app, restart the app when it crashes, and forward HTTP traffic to the app. For more information, see ASP.NET Core Module.
Nginx with Kestrel
For information on how to use Nginx on Linux as a reverse proxy server for Kestrel, see Host on Linux with Nginx.
Apache with Kestrel
For information on how to use Apache on Linux as a reverse proxy server for Kestrel, see Host on Linux with Apache.
If ASP.NET Core apps are run on Windows, HTTP.sys is an alternative to Kestrel. Kestrel is generally recommended for best performance. HTTP.sys can be used in scenarios where the app is exposed to the Internet and required features are supported by HTTP.sys but not Kestrel. For information on HTTP.sys features, see HTTP.sys.
HTTP.sys can also be used for apps that are only exposed to an internal network.
ASP.NET Core server infrastructure
The IApplicationBuilder available in the
Startup.Configure method exposes the ServerFeatures property of type IFeatureCollection. Kestrel and HTTP.sys (WebListener in ASP.NET Core 1.x) only expose a single feature each, IServerAddressesFeature, but different server implementations may expose additional functionality.
IServerAddressesFeature can be used to find out which port the server implementation has bound at runtime.
If the built-in servers don't meet the app's requirements, a custom server implementation can be created. The Open Web Interface for .NET (OWIN) guide demonstrates how to write a Nowin-based IServer implementation. Only the feature interfaces that the app uses require implementation, though at a minimum IHttpRequestFeature and IHttpResponseFeature must be supported.
When using Visual Studio, Visual Studio for Mac, or Visual Studio Code, the server is launched when the app is started by the Integrated Development Environment (IDE). In Visual Studio on Windows, launch profiles can be used to start the app and server with either IIS Express/ASP.NET Core Module or the console. In Visual Studio Code, the app and server are started by Omnisharp, which activates the CoreCLR debugger. Using Visual Studio for Mac, the app and server are started by the Mono Soft-Mode Debugger.
When launching an app from a command prompt in the project's folder, dotnet run launches the app and server (Kestrel and HTTP.sys only). The configuration is specified by the
-c|--configuration option, which is set to either
Debug (default) or
Release. If launch profiles are present in a launchSettings.json file, use the
--launch-profile <NAME> option to set the launch profile (for example,
Production). For more information, see the dotnet run and .NET Core distribution packaging topics.