Deploying ASP.NET Core Applications To IIS

Unlike its predecessor ASP.NET, ASP.NET Core is not "hosted" inside of IIS or for that matter any incarnation of a third-party web server. Instead, ASP.NET Core runs as a standalone process backed by Kestrel.

Kestrel is a cross-platform HTTP server based on libuv, a cross-platform asynchronous I/O library. Web server implementations in ASP.NET Core

When an HTTP request is made to your ASP.NET Core application, it first hits Kestrel. Kestrel then manages that request and passes it your application code. Your application code processes that request and sends a response back up the pipeline.

Network <= HTTP => Kestrel <= HttpContext => Application Code

Kestrel's primary focus is performance and it is not intended to be a feature rich option when it comes to exposing your application to the public. Because of this, we need to introduce a new layer to the pipeline that will act as a reverse proxy server. We introduce this layer because with it, typically comes a server that can handle all the additional features needed to safely and efficiently expose our applications to the public.

Network <= HTTP => Reverse Proxy Server <= HTTP => Kestrel <= HttpContext => Application Code

Because ASP.NET Core is cross-platform, we have a number of servers we can choose from such as IIS, Apache, and Nginx. The primary focus of this post will be to show how to setup IIS to proxy accordingly. If you are interested in Nginx, the following posts will be of value.

Setup

In order to get IIS and the server it lives on in a state that it will face your ASP.NET Core application to the public, we need to install three things.

  1. .NET Core Runtime
  2. .NET Core Library
  3. ASP.NET Core Module

The ASP.NET team has bundled these three items up into package named .NET Core Windows Server Hosting. You can install the package using that executable but like anything else I do, I like to use Chocolatey whenever possible. To do so, run the following command.

choco install dotnetcore-windowshosting -y

In some cases, this package actually lags behind the official .NET Core SDK. Depending on the version of .NET Core your application is running on, you might have to manually update the SDK from the official download site or run the following Chocolatey command.

choco install dotnetcore-sdk -y

After your installs complete, we should be ready to deploy your site to IIS.

Deploying to IIS

Confirmation

Open up your instance of IIS, head to the Modules section and confirm the AspNetCoreModule is available. If you do not see it, you might have to restart IIS before it is properly loaded.

IIS Module

Deploying

Regardless of how you deploy your application, be it manually, through continuous integration, or by Web Deploy, the following will need to happen.

Creating A Site

  1. Right-Click the Sites node in IIS and select Add Website.
  2. Configure your site accordingly.
IIS Create Site

Configuring You Application Pool

When you create a site, it automatically creates an Application Pool to run it under. Head to the Application Pool section of your IIS portal, find the newly created Application Pool and ensure it matches the following configuration.

IIS Create Site

That is it! Your .NET Core application will now be fronted by IIS affording you the opportunity to surround it with any features that are available inside of IIS. Pretty simple, right!

As always, any comments or questions, feel free to leave them below.