Deploy .Net Core application to IIS: Step by step guide

iis11

In my previous post, I have mentioned how to create Serverless .Net Core application which you can find here and you can find my all .Net Core posts here.

In this post, I will explain how to host\deploy your .Net Core 2.0 application to IIS.

prerequisite:

  • Visual studio 2017 community edition, download here
  • .Net Core 2.0 SDK from here (I have written a post to install SDK here)
  • Make sure you have enabled the Web Server (IIS) role and established the role services

Install .NET Core Windows Server Hosting Bundle

Since .Net Core is a new framework, at this moment IIS is not aware of how to run .Net Core applications. So we need to inform IIS to set up an environment for the .Net Core applications.

For this, we need to install .Net Core Windows Server Hosting bundle which will install the .NET Core runtime, libraries, and the ASP.NET Core module for IIS.

Please note that this is a very important step and you must install the bundle before you publish the application on IIS.

You can download it from here(download will start once you click the link):

.NET Core Windows Server Hosting bundle

Wait till the installation is over:

iis5

Once the installation is completed, either restart your system or run below commands in sequence in command prompt:

  • net stop was /y
  • net start w3svc

The first command will stop the World Wide Web publishing service and the second command will start the service again.

Create the Web application using .Net Core 2.0 template in VS 2017

Once you have all these installed, open your Visual Studio 2017 -> Create New Project -> Select Core Web application:

iis1

Click on Web Application in next window and then click on Ok:

iis2

Visual Studio will create a well-structured application for you.

Right click on the solution and click on Publish:

iis3

In next window, click on Folders and give the folder path. I created Publish folder under wwwroot folder:

iis4

It will publish the application on the above-mentioned path:

iis6

Create Website on IIS

Open your IIS Manager and add new website:

iis7

Now go to Application Pools panel, open the Edit Application Pool window by right-clicking on the website’s app pool and selecting Basic Settings and set .NET CLR version to No Managed Code:

iis8

Check if .Net Core Windows Server Hosting bundle is installed properly

Next step is to check whether the hosting bundle which we installed earlier is installed properly or not.

For this click on Modules(in IIS Manager) of your newly created website and search for AspNetCoreModule. If it is available, it indicates that IIS is now aware of how to run a .Net Core application.

iis9

You might be wondering what is Asp .Net Core Module?

  • ASP.NET Core Module lets you run ASP.NET Core applications on IIS for what it’s good for i.e. security, manageability, and lots more
  • On the other hand, ASP.NET Core Module lets you run ASP.NET Core applications using Kestrel for what it’s good at for example being really fast
  • Thus it is getting the benefits of both technologies at once
  • Asp .Net Core Module handles all incoming traffic to IIS and acts as the reverse proxy that knows how to hand the traffic off to your ASP.NET Core application

You may have noticed that when we published the code to a particular folder, a web.config was created in which you can see aspNetCore under Handler section as below. This is only used when deploying your application to IIS and It registers the AspNetCoreModule as an HTTP handler.


<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<strong><add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /></strong>
</handlers>
<aspNetCore processPath="dotnet" arguments=".\NeelCorePublishIIIS.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>

That is it.

Just load your IIS site and it should load just fine:

iis10

Now the application is hosted on IIS.

Hope it helps.

 

 

31 thoughts on “Deploy .Net Core application to IIS: Step by step guide

  1. All I got was ……..
    This page isn’t working
    If the problem continues, contact the site owner.
    HTTP ERROR 401

    Like

      1. Neel:

        My bad. The port I initially chose had a web service attached to it. I changed ports and the website opened correctly. I appreciate your response.

        Mark

        Like

  2. I simply wanted to thank you so much again. Thanks for sharing this valuable information.Net Core application to IIS: Step by step guide.
    I hope you will keep sharing more such informative articles.
    I would like to know more about ASP.NET CORE PITFALLS. Can you share info plz

    Like

    1. It might’ve required a reboot for me. Restarting IIS svc multiple times didn’t help, but after reboot I finally saw the component registered in IIS as well as web.config created. Thanks!

      Like

  3. Only you have mentioned a restart of server/system and that is the key. I was struggling from a week and at end when saw your blog and just restarted server as that was only thing I haven’t done. And Voila!! Thanku sooo much!

    Liked by 1 person

  4. Thank you so much! Yes, you are right, to run .net Core, we need to run it to no Managed Code. Previously, I always receive 502 error when deploying .net core on Asphostportal server. And finally found this simple issue. Great!

    Like

Leave a comment