Hosting ASP.NET Core Web API on IIS
This article will help you to host ASP.NET core Web API in IIS by using Visual Studio.
Asp.net core web application deployment is not the same as Asp.Net, there are some few more components that are needed with hosting your asp.net core 2.0 applications on IIS. Before deploying, you must install a bundle which is required to host Asp.Net Core 2.0 application on IIS and that is, .Net Core Windows Server Hosting. This bundle will install.Net Core Runtime which gives all the necessary libraries at runtime, Net Core Library, and Asp.Net Core Module.
Download Link for “Microsoft .Net Core Windows Server Hosting” bundles.
Warning
Please do confirmed you have restarted your computer before moving to the next step after the installation of “Microsoft .Net Core Windows Server Hosting” bundles.
For this demonstration, I am using the same Asp.Net Core 2.0 web API (Image Uploads) which I have built in the previous article. To learn how to create Image Upload Rest API in Asp.net core, please refer to the following article:
Images Upload REST API using ASP.NET Core
Let’s open your project on visual studio.
Steps:
- Right click on your project and click on Publish.
- Select folder that you want to store your published file. Here I am going to store my published file on F:\ImageUploadDemo.
- Click on publish.
- It takes some time to publish your Web Application.
Host WebAPI in IIS
- Open IIS manager by clicking Windows start -> Search IIS and open it.
- If IIS is not installed on your Computer click here to install.
Now, go to IIS manager and right click on sites and select Add Web site.
Enter details as shown in below screenshot
- Enter site name as ImageUploadAPI
- Change the application pool to DefaultAppPool
- Select the physical path of folder which contains published ASP.NET Web API. I entered as F:\ImageUploadDemo
- Enter port number on you wish to host API. I use port as 8084.
- And click on ok
Browse ASP.NET Core Web API through IIS
Your Web API are now hosted in IIS. Now You can browse it through IIS or browser.
From IIS manager -> Select Sites -> right click on ImageUploadAPI (created in previous step) -> Select Manage Web Site-> and select Browse.
It will redirect to http://localhost:8084. As I have wrote in Startup.cs. It will show the message “MVC didn't find anything!”
app.Run(async (context) =>
{
await context.Response.WriteAsync("MVC didn't find anything!");
});
Summary:
In this article, we learned how to host our asp.net core web API on IIS.
Happy Coding!!!