.Net Web API No HTTP resource was found that match

2019-04-28 03:22发布

I am working on .Net Web API which is working fine in debug as well as on localhost IIS but when i publish this to server it starts giving following error :-
"Message": "No HTTP resource was found that matches the request URI

On server, we have application folder under default site for this API, but it's working fine in application folder under local IIS's default site so that should not be the problem.

Now i tried setting proper verb in handler as specified in following url but didn't work:
HTTP 404 Page Not Found in Web Api hosted in IIS 7.5

Also i have MVC4 installed on server as suggested on following url:
.NET Web Api - 404 - File or directory not found

Also WebDav module, handler may give error so i also tried removing it but it's giving same error.

Here is the Web.config section for module, handler settings :-

<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="*" modules="IsapiModule" 
       scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" 
       preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="*" modules="IsapiModule" 
       scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" 
       preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

I am not playing with routes anywhere. Am i missing something regarding settings/configuration in web.config or server IIS ?

3条回答
该账号已被封号
2楼-- · 2019-04-28 04:05

This works for me:

<remove name="WebDAV"/>

I don't know why it is installed on the server. But this seems to have interference with extensionless handlers

From IIS (http://www.iis.net/learn/install/installing-publishing-technologies/installing-and-configuring-webdav-on-iis):

Microsoft released a new WebDAV extension module that was completely rewritten for Internet Information Services (IIS) 7 and above on Windows Server® 2008. This new WebDAV extension module incorporated many new features that enable Web authors to publish content better than before, and offers Web administrators more security and configuration options. Microsoft has released an update to the WebDAV extension module for Windows Server® 2008 that provides shared and exclusive locks support to prevent lost updates due to overwrites.

查看更多
Deceive 欺骗
3楼-- · 2019-04-28 04:08

Change to:

<validation validateIntegratedModeConfiguration="false" />
<modules>
  <remove name="WebDAVModule"/>
</modules>
<handlers>
  <remove name="WebDAV"/>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
查看更多
在下西门庆
4楼-- · 2019-04-28 04:14

Another potential reason for this is if the

    GlobalConfiguration.Configure(WebApiConfig.Register);

is after

    RouteConfig.RegisterRoutes(RouteTable.Routes);

in global.asax.cs

It needs to be before, otherwise the default RouteConfig route 'eats' the WebAPI route - and attempts to map API requests to a controller called API...

查看更多
登录 后发表回答