Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP 404 Page Not Found in Web Api hosted in IIS 7.5

I have a Web Api application. It works perfectly well when I tested it using the VS 2010 debugging dev server. But I now deployed it to IIS 7.5 and I am getting a HTTP 404 error when trying to access the application.

Here is my web.config

<?xml version="1.0" encoding="utf-8"?> <configuration>   <connectionStrings>     <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-FlowGearProxy-20123141219;Integrated Security=True" providerName="System.Data.SqlClient" />   </connectionStrings>   <appSettings>     <add key="webpages:Version" value="2.0.0.0" />     <add key="webpages:Enabled" value="true" />     <add key="PreserveLoginUrl" value="true" />     <add key="ClientValidationEnabled" value="true" />     <add key="UnobtrusiveJavaScriptEnabled" value="true" />   </appSettings>   <system.web>     <compilation debug="true" targetFramework="4.0" />     <authentication mode="Forms">       <forms loginUrl="~/Account/Login" timeout="2880" />     </authentication>     <pages>       <namespaces>         <add namespace="System.Web.Helpers" />         <add namespace="System.Web.Mvc" />         <add namespace="System.Web.Mvc.Ajax" />         <add namespace="System.Web.Mvc.Html" />         <add namespace="System.Web.Routing" />         <add namespace="System.Web.WebPages" />       </namespaces>     </pages>   </system.web>   <system.webServer>     <validation validateIntegratedModeConfiguration="false" />     <modules runAllManagedModulesForAllRequests="true" />   </system.webServer> </configuration> 
like image 736
Armand Avatar asked Mar 14 '12 13:03

Armand


People also ask

Why am I getting a 404 error on my website?

"It might be a case that you are redirecting a user to the link [you are facing 404] as a default page" Please Sign up or sign in to vote. Indeed, the problem was with the way I had hosted the sites in my application.

Why is my API url not working on my website?

I believe this is due to the change in the URL routing as follows: If you move the Web API project to it's own website running on a different port it seems to work. Additional note: I had further complicated the issue by adding api as the alias of an application within my website which caused the effective URL to be:

Does Swagger return a 404 error when deploying to IIs?

However, after publishing and deploying onto IIS Site, it returns a 404 error. The Swagger.json is formed, the Swagger UI is served correctly on https://domain:<port>/API/docs/index.html but when trying out https://domain:<port>/API/docs/<command> responds back with 404.

Is it possible to deploy a web API in IIS?

We developed a web api in .net core and deployed it to our test server (hosted in IIS) with no issue. It is callable from Postman and all seemed good. We now have a new server that would be the PROD server Windows 2019 with IIS installed.


1 Answers

I was struggling with this as well. Fortunately, Steve Michelotti documented a solution that worked for me here.

At the end of the day, I enabled all verbs (verb="*") to the ExtensionlessUrlHandler-Integrated-4.0 handler in my web config.

<system.webServer>     <validation validateIntegratedModeConfiguration="false" />     <modules runAllManagedModulesForAllRequests="true" />         <handlers>             <remove name="ExtensionlessUrlHandler-Integrated-4.0" />             <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />         </handlers> </system.webServer> 

Others have pointed out that having WebDAV enabled causes issues. Fortunately, I did not run into that issue as well.

like image 76
Kevin Ortman Avatar answered Sep 18 '22 16:09

Kevin Ortman