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.
- Developing A .NET Core Site In Windows and Deploying It To A Budget Linux Host
- Deploying An ASP.NET Core Site, You're Still Doing It Wrong: Part 1
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.
- .NET Core Runtime
- .NET Core Library
- 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
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.
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
- Right-Click the Sites node in IIS and select Add Website.
- Configure your site accordingly.
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.
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.