Web Api Calls 404 Returns on Server

I know that others have asked about this many times on this site, but not a single solution that I have seen so far works, so I'm here.

I have several api web routes created in mvc 4 project. Here is a sample:

routes.MapHttpRoute(name: null, routeTemplate: "Client/Accounts/Save", defaults: new { controller = "AccountsApi", action = "SaveAccount" }); 

Corresponds to the following controller and action:

 public class AccountsApiController : ApiController { [HttpPost] public object SaveAccount([FromBody] Account input) { ..... 

This works when running on the built-in web server VS and local (Windows 7) installing IIS7.5 without any fancy actions, but gives 404 when working in IIS7 on the server 2008 R2.

information:

  • MVC4 is installed on the server
  • The application is in the application pool with built-in mode and v4 framework

What I tried:

  • It is played with paths to know that this is not a routing problem.
  • Set <modules runAllManagedModulesForAllRequests="true" /> (by default, anyway)
  • Looked this
  • Made by aspnet_regiis -ir dance
  • User errors are turned off, debug = false compilation - if that matters.
  • There are only custom api routes, don't catch everyone.
  • IIS logs indicate only 404, as you would expect; nothing in the system event logs

Api uses only GET and POST tags, none of which work. It is also worth mentioning that all calls are made through ajax.

system.web , system.webServer , runtime sections from config:

 <system.web> <compilation debug="false" targetFramework="4.0" /> <customErrors mode="Off" /> <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.Optimization" /> <add namespace="System.Web.Routing" /> <add namespace="System.Web.WebPages" /> </namespaces> </pages> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules runAllManagedModulesForAllRequests="true" /> <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="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" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> </system.webServer> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> 

Any suggestions are extremely appreciated. Thanks.

Update

I repeated one of my controllers to use only HttpResponseMessage and HttpRequestMessage

 [HttpGet] public HttpResponseMessage GetAccount(HttpRequestMessage message) { message.CreateResponse(.... 

and again it works, as expected, when running locally (both cassini and the full local installation of IIS on Win7), but it crashes when you click on the server.

+4
source share
2 answers

Failed to resolve this issue. Almost certainly up to some obscure thing not installed or enabled on the server. Very frustrating as other Web Apis already work in one box.

It was not possible to spend more time on this, so just override it with a Service Stack that just works.

0
source

Update: I just noticed that you said that the GET methods do not work either, in which case this advice is probably not suitable for you.

Try changing the method signature to

 [HttpPost] public HttpResponseMessage SaveAccount(HttpRequestMessage request) { } 

This will allow you to eliminate the problem with binding action / model selections. If it still does not match, I suggest you turn on the author of the trace and find out why it does not find the controller. http://nuget.org/packages/Microsoft.AspNet.WebApi.Tracing/

If it matches the signature above, take a look at this blog post at http://www.bizcoder.com/?p=259 for further suggestions on debugging serialization issues.

+1
source

All Articles