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.

 

 

Advertisements

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

      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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s