Solution To Common Errors While Hosting Web API In IIS

Introduction

While publishing Web API using Visual Studio, you may run into some errors. This article helps to provide the solution to the possible errors that will occur.

Let’s get into the action.

When you publish the Web API from Visual Studio, the following error may possibly come up.

  1. Output class library not set error while hosting web API

    OutputPath property is not set for project 'Company.Directory.Web.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration=Release Platform='AnyCPU'. You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project.

    Solution

    When you try to publish for the first time, one of the reasons for the above error to pop up is due to the incorrect settings in .csproj.user file of the solution.

    Open the .csproj.user file in the solution and change the settings in the file.

    Add the following code in the file.
    1. <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">  
    2.     <DebugSymbols>true</DebugSymbols>  
    3.     <DebugType>full</DebugType>  
    4.     <Optimize>false</Optimize>  
    5.     <OutputPath>bin\</OutputPath>  
    6.     <DefineConstants>DEBUG;TRACE</DefineConstants>  
    7.     <ErrorReport>prompt</ErrorReport>  
    8.     <WarningLevel>4</WarningLevel>  
    9. </PropertyGroup>  
    10. <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">  
    11.     <DebugType>pdbonly</DebugType>  
    12.     <Optimize>true</Optimize>  
    13.     <OutputPath>bin\</OutputPath>  
    14.     <DefineConstants>TRACE</DefineConstants>  
    15.     <ErrorReport>prompt</ErrorReport>  
    16.     <WarningLevel>4</WarningLevel>  
    17. </PropertyGroup>  
    18. <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Dev|AnyCPU'">  
    19.     <DebugSymbols>true</DebugSymbols>  
    20.     <OutputPath>bin\</OutputPath>  
    21.     <DefineConstants>DEBUG;TRACE</DefineConstants>  
    22.     <DebugType>full</DebugType>  
    23.     <PlatformTarget>AnyCPU</PlatformTarget>  
    24.     <ErrorReport>prompt</ErrorReport>  
    25.     <CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>  
    26.     <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>  
    27.     <DeployIisAppPath>Port 80/directory/dev</DeployIisAppPath>  
    28. </PropertyGroup>  
  2. Solution to 500.19 internal server error while hosting Web API



    Solution

    The above error will pop up when you do not have the permission to access the folder/web.config file.

    1. In Windows Explorer, locate the web.config file that is associated with the Web site. 
    2. Right-click the web.config file 
    3. Click Properties. 
    4. Click the Security tab, and then click Edit. 
    5. Click Add. 
    6. In the Enter the object names to select box, IUSR, click Check Names, and then click OK. 
    7. Click to select the Read check box, and then click OK. 
    8. In the Web.config Properties dialog box, click OK.

  3. Solution to 500.21 internal server error while hosting Web API



    Solution

    One of the reasons for the error 500.21 Internal Server Error to pop up, is when ASP.NET is not installed completely in your system.

    1. Run the command prompt as administrator.
    2. Type the line in the command prompt below any one.

      %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
      or
      %windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -I


  4. Solution to login for application pool access error is denied while hosting Web API



    Solution

    Create the application pool in IIS by selecting the .NET version which your project supports. When creating the site in the default application in IIS for Web API, select the application pool which you have created. The above error will pop up if the application pool which you have created has a built in account selected.

    For reference - go to: "Advanced Setting->Process->Identity” of the application pool which you have created. Change the application pool identity to custom account and click on set button to provide the account credentials. Once you have set the setting, refresh/reset IIS to resolve the above error.

  5. Access Denied Error while hosting Web API


    Solution

    The above error will pop up if the solution directory (folder) doesn’t have required permissions.

    To resolve the issue follow the steps given in “500.19 : internal server error”.