Deploy ASP.NET Core Web Application to IIS in 5 Easy Steps
Once you finish developing your ASP.NET Core web application the next step
would be to deploy it under the IIS. Although this process is quite similar to
traditional ASP.NET Web Forms or MVC applications, there are a few things you
need to be aware of. To that end this article explains how an ASP.NET Core web
application can be deployed under IIS.
The biggest difference between a traditional ASP.NET web application and an
ASP.NET Core application is probably this -
An ASP.NET Core web application is hosted and run by
Kestrel, an inbuilt web server. This means technically you don't need IIS at
all to run your web applications. Your requests can be directly handled by
Kestrel. However, you would still want to go with IIS because unlike Kestrel,
IIS in a full-blown web server with a lots of features and management user
interface.
When you host your ASP.NET Core web applications under IIS, IIS is basically
acting as a
reverse
proxy. The following figure shows the relation between IIS and Kestrel.
As you can see IIS is simply forwarding your requests to the Kestrel. For all
this to work as expected the IIS makes use of AspNetCoreModule component. This
component gets installed when you install the .NET Core framework or you can
install it using this.
Ok. Now that you have got some idea as to what we are attempting to do, let's
begin with a simple example.
1. Create a new ASP.NET Core web application
Begin by creating a new ASP.NET Core web application. You can use the Web
Application template to do that.
Once created, open Program.cs file and ensure that the following entries are
present.
Then open Project.json and ensure that the following entries are present.
This will ensure that publishing wizard of Visual Studio copies the view
files and configuration files to the destination.
2. Publish the web application to a folder
For this simple example. let's not add any code as such and go straight to
the publishing. Select Build > Publish menu option to open the Web Site
deployment wizard. This is the same wizard that you used for traditional ASP.NET
web forms and MVC applications. Using this wizard publish the web application to
a physical folder (see figure below).
Now you are ready with all the deployables needed to deploy your web
application under IIS.
3. Create an IIS website
Open IIS manager from the Control Panel > Administrative Tools. Then right
click on the Sites node and select Add Website menu option. Doing so will open
the following dialog:
Specify a website name and under the Physical path area pick the same folder
where you published your application in the previous step. You may also consider
changing the port number if you so wish. Clicking OK will create the IIS website
for you.
Once created go to the Modules option of the website and ensure that
AspNetCore is listed in the module list.
4. Configure the website's application pool
As discussed at the beginning of this article, IIS is simply acting as a
reverse proxy. So, IIS doesn't play any active part in executing your
application code. That's why you need to configure your IIS website's
application pool accordingly.
To do this configuration, locate the Application Pools node immediately
under IIS manager (located above the Sites node). Then go to your website's
entry there, right click on it and select Basic settings option. This will open
the following dialog:
Under .NET CLR version pick No managed Code and click OK.
5. Access the website from a browser
Now open a browser window, type in the website's URL and hit enter. For
example, the following figure shows the default web application created earlier
being accessed at http://localhost:9000/home/index
That's it for now! Keep coding!!