Tutorial – Publish ASP.NET Web API in IIS 8.5 and Windows 8.1

Some of my previous posts involved in web services made by ASP.NET Web API and I have received some feedback that it’s difficult to make the code run. The readers don’t know how to publish the sample web service which is included in source file. Therefore in this post I will show you how to publish a ASP.NET Web API service to localhost (your local computer). The tutorial is written for my current environment with Windows 8.1 and IIS 8.5. If you have another system and don’t find out how to follow a certain step in tutorial, make a comment below. Maybe I can help.

1. Source code

1.1. Visual Studio

I’m using Visual Studio 2012 Ultimate Update 3.
Visual Studio 2012 Update 3
My web services base on templates of this version of Visual Studio therefore if you have another version of Visual Studio, maybe you have to install templates to open the solution. However, for following version you don’t need to install any prerequisite
– Visual Studio 2013 (all versions)
– Visula Studio 2012 (all versions)

If you’re using Visual Studio 2010, let’s Windows Update run until there is no required updates anymore. Windows Update will automatically get and install all updates for Microsoft products including your Visual Studio. Try to open the solution, if Visual Studio still can’t load it, go to http://www.asp.net/downloads, download the latest ASP.NET SDK and install. The SDK contains all of libraries and templates required for ASP.NET MVC.

1.2. Nuget

In previous step, we prepare an environment so that we can load ASP.NET Web API project in Visual Studio. The ASP.NET Web API libraries and its all dependencies are delivered and versioned through NuGet. Therefore if your Visual Studio still don’t have this plugin installed, let’s install it from http://www.nuget.org/. When the plugin is installed successfully, you’ll have a menu ‘Library Package Manager’ under ‘TOOLS’.


For NuGet packages, I also set that NuGet should automatically download the missing packages

NuGet download missing packages

So,in the source code, I will intentionally delete the packages folder to keep size as small as possible. After downloading the source file, if you can’t compile the project, don’t be angry. Right click on the solution, click on “Rebuild Solution”, NuGet will download all missing packages and the solution will be compiled successfully.

Rebuild solution

2. Internet Information Services (IIS)

2.1 Installation

In the first part, I show you the prerequisites to compile a web service made by ASP.NET Web API. Now you need a web server to host your web service. All you have to do is installing IIS on your local computer. In Control Panel –> Programs and Features –> Turn Windows features on or off –> Internet Information Services and then activate the features as following images.

Internet Information Services

That’s all. If you’re lucky, after installation, open your web browser, enter http://localhost, you’ll get you’ll get a welcome screen of IIS


2.2 Publishing

To publish a web service to IIS, remember to start your Visual Studio under Administrator. Right click on project and choose publishing

Publish to IIS

On next window, create a new profile if you still don’t have any

Create new profile

For connection settings, you can use the following setting for example

Profile connection

The “Site name” consists of 2 components : the website and the application name. You can change the application name as you want, but the website “Default Web Site” should work in most of cases if you don’t change anything in IIS. To check if the publishing progress is successful, open IIS Manager

IIS Manager

On the left panel, expand the tree node of server to “Default Web Site”, there is a sub node with name of your application. Note that the icon must be an application icon (a sheet on earth). If the icon is a folder icon, that means the publishing failed, you have to convert to application by right click on folder and “Convert to application”

Convert to application

2.2 Permission

After publishing the web service to IIS, if the web service allows user to upload files to server, you have to configure permission in App_Data folder so that IIS can store files. Browse to C:\inetpub\wwwroot\{YOUR_APPLICATION}\App_Data, right click on “uploads” folder –> Tab Security –> Be sure that permission of IIS_IUSRS has “Full control”

IIS Permission

3. Error

If you are lucky, you won’t receive any error during publishing. However I just write down some typical errors and their solutions which you may encounter.

3.1 IIS + Windows 7 + “HTTP Error 503. The service is unavailable”

IIS Manager –> Application Pools –> DefaultAppPool –> Advanced Settings -> “Load User Profile” = false.

IIS + Windows 7 + HTTP Error 503. The service is unavailable

3.2 IIS + Windows 7 + “HTTP Error 500.19 – Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid”

In web.config there is a problem with <modules runAllManagedModulesForAllRequests=”true”/>


%windir%\system32\inetsrv\appcmd unlock config -section:system.webserver/modules

Activate modules

3.3 ASP.NET 4 was not registered in IIS

Had to run the following command in the command line/run

32bit (x86) Windows

%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -ir

64bit (x64) Windows

%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir

9 thoughts on “Tutorial – Publish ASP.NET Web API in IIS 8.5 and Windows 8.1”

  1. I am newbie in asp and not good in English.whould you mind please help me to make a setup? thank you in advance.

  2. I was getting the error: HTTP 500.19 0x80070005 Error

    Solved by changing the Application Pool of my running application. On IIS, select your application pool then open Advanced Settings and change Enable 32-bit Applications to True

  3. Really helpfull. Was stuck since a long time. Got break through after looking this post.
    Thanks a lot for sharing the info.

  4. i am getting these error when trying to rebuild the solution as an administrator

    Error 1 NuGet Package restore failed for project Upload File To ASPNET Web API: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.. 0 0
    Error 2 Could not write lines to file “obj\Debug\Upload File To ASPNET Web API Models.csproj.FileListAbsolute.txt”. The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. Upload File To ASPNET Web API Models
    Error 3 Could not write lines to file “obj\Debug\Upload File To ASPNET Web API Client.csproj.FileListAbsolute.txt”. The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. Upload File To ASPNET Web API Client
    Error 16 Metadata file ‘D:\Downloads\hintdesk-dotnet-upload-files-to-asp.net-web-api-service-eac4d56b56d5\hintdesk-dotnet-upload-files-to-asp.net-web-api-service-eac4d56b56d5\Upload File To ASPNET Web API Models\bin\Debug\Upload File To ASPNET Web API Models.dll’ could not be found D:\Downloads\hintdesk-dotnet-upload-files-to-asp.net-web-api-service-eac4d56b56d5\hintdesk-dotnet-upload-files-to-asp.net-web-api-service-eac4d56b56d5\Upload File To ASPNET Web API\CSC Upload File To ASPNET Web API

  5. @Marium: Your project path is too long “D:\Downloads\hintdesk-dotnet-upload-files-to-asp.net-web-api-service-eac4d56b56d5\hintdesk-dotnet-upload-files-to-asp.net-web-api-service-eac4d56b56d5\Upload File To ASPNET Web API Models\bin\Debug\”

    Shorten your path by renaming the the parent folder.

Leave a Reply

Your email address will not be published. Required fields are marked *