Publish And Host ASP.NET Web API

Introduction

This article introduces how to publish and host an ASP.NET Web API on an IIS server and how to call it. We will use the same example used in the article Getting Started With ASP.NET Web API. First of all, we publish ASP.NET web API and then will host it on the server.

Publish Web API from Visual Studio

To publish ASP.NET web API from Visual Studio, here are the steps,

Step 1. Build ASP.NET Web API project /solution in Release mode.

Step 2. Right-click on the Web API project and click the “Publish” menu.

Publish
Figure 1: Publish ASP.NET Web API project

Step 3. Now open the Publish Web pane and choose the Profile tab from the left tab. There is a “Select or import a public profile” in which you can either choose an existing one or create a new publish profile as in the following image.

Publish Web
Figure 2: Publish Profile for Web API

Now click “OK” and move to the Connection tab in Publish Web.

Step 4. Now we choose File System in the publish method and choose the desired location in Target Location which we will use to map IIS.

File System
Figure 3: File System to publish Web API

Step 5. Now we choose configuration mode Release as in the following image and click on the Next button.

Release
Figure 4: Configuration mode for Web API setting

There are some options such as Delete all existing files prior to publishing which means it deletes all existing files in the target location publish folder and creates new files.

Step 5. Now we get the publish preview which shows the publish path and profile name.

publish preview
Figure 5: Publish Preview for Web API

Now click on the publish button and all published files created at the target location as in the following image,

Target location
Figure 6: Published files for web API

Host Web API on IIS Server

As we have published the code so now we host this code on IIS step by step.

Step 1. Search inetmgr in the search box and click on the IIS manager icon.

Step 2. In the IIS manager, Right click on Sites under the Connections pane as in the following image,

 IIS manager
Figure 7: IIS Manager

Step 3. We have the following, now fill in all the information that is required to host API on the server.

  • Site name: Name of site
  • Application pool: .NETv4.5 (version of .net framework on which API runs)
  • Physical path: Path of the published API code and map to the directory which has Web. config file.

API code
Figure 8: API host on IIS server.

Now click on OK and access API’s GET request method using the following URL:

http://localhost/api/home/getStudent


Similar Articles