Question

I am using MVC4's WEB API to expose a controller.

Initially I created created a MVC4 WEBAPI project, set the project not to open any web page, wait for an external app to call the URL (WEB API). The project in VS2010 is set to run from IIS7 Express, not VS2010's Dev Server. This works OK, the browser prompts me to down load a file. Which is OK for me, as the browser does not know what to do with the returned data (RAW TEXT).

Next, I created an AREA in the MVC4 project area, then added a controller (WEB API type).

Then I once again ran the project and in a browser entered the the URL (WEB API). And it fails.

Ed.

Was it helpful?

Solution

The DefaultHttpControllerFactory doesn't work with Areas by default. To get this functionality you have to write your custom HttpControllerFactory.

You can find how to do this at the post How to create HttpControllerFactory to support Areas

OTHER TIPS

While it is possible to place WebApi Controllers in different Areas, ASP.NET MVC 4 RC will still treat these ApiControllers as if they all reside in the same namespace. This is a limitation of the DefaultHttpControllerSelector, which is responsible for selecting the appropriate ApiController.

Fortunately, you can inject your own implementation of this class. In fact, I've already encountered this very issue and written an "area aware" HttpControllerSelector. You can find a blog post of mine about this issue and its solution here:

http://blogs.infosupport.com/asp-net-mvc-4-rc-getting-webapi-and-areas-to-play-nicely/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top