Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

all requests to asp net web api return 404 error

all requests to asp net web api return 404 error  using -',.net,,,'

I have an ASP.NET MVC 4 web site that includes Web API. The site is developed and tested with Visual Studio 2012 and .NET 4.5 on Windows 8 with IIS Express as web server. In this development environment everything works.

Now it is deployed on a Windows 2008 R2 (SP1) Server with IIS 7.5. .NET 4.0 and 4.5 are installed. The application pool is running with .NET 4.0 in integrated pipeline mode.

In this production environment the MVC web site works, Web API does not. For every request, no matter if GET or POST I get a 404 error. If I just enter a Web API Url in the browser (IE 9 opened locally on the server) to run a GET request I get a 404 page. If I issue a POST request from a Web API client application I get a 404 as well and the message:

  No HTTP resource was found that matches the request URI

I've created a test website with MVC 4 and Web API as well and deployed it on the same server and the Web API works. Web API and MVC assemblies have the same version number in both projects.

Furthermore I have added the Web API Route Debugger to the application. If I use a valid route like http://myserver/api/order/12 I get the following result:

For me this means that the correct route template Api/{Controller}/{Id} has been found and correctly parsed into a controller Order and Id=12. The controller (derived from ApiController) exists in the web assembly where also all MVC controllers are.

However, I don't know what the status 000 could mean and why there is no "Route selecting" section displayed (which is normally the case even if the assembly doesn't contain a single ApiController, see screenshots on the linked page above). Somehow it looks like no ApiController is found or even not searched for or the search fails silently.

The IIS log files don't show anything useful. Changing various application pool settings and using the same app pool for the test and the real application didn't help.

I am currently in the process to remove "features", configuration settings, third party assemblies, etc. from the application to bring it down to the small size of the test application in the end and hoping that at some point it starts to work.

Does somebody have a clue what the issue could be? Also any debugging or logging idea to possibly find the reason is very welcome.


Thanks to Darrel Miller's tip in the comments below I have integrated Tracing for ASP.NET Web Api.

For the (GET) request URL http://myserver/api/order/12 I get the following:

In development environment, successful (in short form):

  Message: http://localhost:50020/api/order/12; Category:
  Controller selection and instantiation...
  Operator: DefaultHttpControllerSelector; Operation: SelectController;
  Message: Route="controller:order,id:12"; Category:
  Operator: DefaultHttpControllerSelector; Operation: SelectController;
  Message: Order; Category: System.Web.Http.Controllers
  Operator: HttpControllerDescriptor; Operation: CreateController;
  Message: ; Category: System.Web.Http.Controllers
  Operator: DefaultHttpControllerActivator; Operation: Create; Message:
  ; Category: System.Web.Http.Controllers
  Operator: DefaultHttpControllerActivator; Operation: Create; Message:
  MyApplication.ApiControllers.OrderController; Category:
  Action selection, parameter binding and action invocation follows...
  Content negotiation and formatting for result...
  Operator: DefaultContentNegotiator; Operation: Negotiate; Message: Typ = "String" ...
  Disposing the controller...
  Operator: OrderController; Operation: Dispose; Message: ; Category:

In production environment, not successful (in short form):

  Message: http://myserver/api/order/12; Category:
  Operator: DefaultHttpControllerSelector; Operation: SelectController;
  Message: Route="controller:order,id:12"; Category:
  The whole part of controller activation, action selection, parameter binding, action invocation is missing and it follows content
  negotiation and formatting for the error message immediately:
  Operator: DefaultContentNegotiator; Operation: Negotiate; Message:
  Type = "HttpError" ... more


asked Oct 19, 2015 by ankitarajoria4
0 votes

Related Hot Questions

Government Jobs Opening