Publish And Host ASP.NET Web API


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

Publish Web API from Visual Studio

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


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

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

                Figure 1: Publish ASP.NET Web API project

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

    publish web
                                                 Figure 2: Publish Profile for Web API

    Now click “Ok” and move on Connection tab in Publish Web.

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

    publish web
                                                Figure 3: File System to publish web API

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

    publish web
                                           Figure 4: Configuration mode for Web API setting

    There are some options such as Delete all existing files prior to publish which means it delete all existing files in target location publish folder and create new files.

  6. Now we get publish preview which shows publish path and profile name.

    publish web
                                                 Figure 5: Publish Preview for Web API

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

    publish web
                                                    Figure 6: Published files for web API

Host Web API on IIS Server

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


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

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

                                                                      Figure 7: IIS Manager

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

    Site name: Name of site

    Application pool: .NETv4.5 (version of .net framework on which API run)

    Physical path: Path of the published API code and map to directory which have Web.config file.

    add website
                                                    Figure 8: API host on IIS server.

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