Deploying ASP.NET Core RC1 Application to IIS

February 14th 2016 ASP.NET Core IIS Visual Studio

If you're used to the old ASP.NET, it's not all that obvious how to deploy an ASP.NET Core application to IIS. Although, there is documentation available for the process, I still struggled a bit, before I got everything working. This post contains the steps I had to take, so that I can simply follow them the next time. At least, until something changes again with one of the future releases.

Preparing the Files in Visual Studio

The first step of publishing your app, once it is ready, is done in Visual Studio's Publish wizard. You invoke it by right clicking the project in the Solution Explorer end clicking on Publish... there. On first start you will need to create a named publishing profile, so that you can only invoke it on subsequent runs.

Since I wanted to manually copy the files to IIS, I selected File System as the publish target. The only changes I made to the defaults are hidden on the Settings page in the collapsed File Publish Options group: I checked both Delete all existing files prior to publish and Compile source files into NuGet packages.

Settings page of Publish wizard

All of the files created by Visual Studio in the selected Target location need to be copied to a server or directory where IIS can access them.

Configuring IIS

For ASP.NET Core applications to work in IIS, HTTP Platform Handler needs to be installed in IIS. It is available separately in 32-bit and 64-bit versions. Before continuing you should make sure it is correctly installed by checking the list of Modules at the server level in IIS Manager.

HTTP Platform Handler module in IIS

Now you can create a new web site or application and set its Physical path to wwwroot (not approot!) subfolder inside the publish folder.

Workaround to Deploy as an Application

If you decided to publish the app as a new web site, that's all you needed to do and the application already works. If you deployed it as an IIS application instead, you will receive a 404 - Page Not Found error when navigating to the newly created application because of a bug in IIS integration.

Until it gets fixed (probably in RC2), you can apply a workaround to your code. Hardcode the relative path of your IIS application in the Startup class, as follows:

public void Configure(IApplicationBuilder app)
    // relative path to you IIS app as first argument
    app.Map("/app-path", ConfigureRoot);
    // call this to keep your app working from VS (as web site root)

// Contents of your original Configure method, renamed to your liking 
public void ConfigureRoot(IApplicationBuilder app)
    app.UseMvc(rb =>
            name: "default",
            template: "{controller}/{action}/{id?}",
            defaults: new { controller = "Home", action = "Index" });

Deploying the app with this change into an IIS application with matching relative path will now work as expected.

Get notified when a new blog post is published (usually every Friday):

If you're looking for online one-on-one mentorship on a related topic, you can find me on Codementor.
If you need a team of experienced software engineers to help you with a project, contact us at Razum.
Creative Commons License