Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I combine a MVC4 site and a WebAPI site under the same IIS website?
    text
    copied!<p>I have a project (named <code>Product.Api</code>) that has some controllers used for our WebAPI site. The controllers are in a namespace <code>Product.Api.Controllers</code>. The project also has some other helper stuff as well. This is compiled into a library.</p> <p>I also have another regular ASP.NET MVC4 website named <code>Product.Web</code>. This has Controllers (under the namespace <code>Product.Web.Controllers</code>), Models and Views (in its corresponding folders). It also has a <code>Global.asax.cs</code> which has the routing information.</p> <p>When the site is created in IIS (.NET 4.5, IIS7, integrated mode, etc), I copy the <code>Product.Api</code> dll into the bin folder. The <code>Product.Web</code> is the main site. </p> <p>Now I want the url <a href="http://www.product.com/api/" rel="nofollow">http://www.product.com/api/</a>{Controller}/{id} to map to the WebAPI stuff and <a href="http://www.product.com/" rel="nofollow">http://www.product.com/</a>{Controller}/{Action}/{id} to map to the regular MVC. </p> <p>This is what I have right now as my routes:</p> <pre><code>routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new {id = RouteParameter.Optional} ).Constraints["Namespaces"] = new string[] { "Product.Api.Controllers" }; routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } , namespaces: new[] { "Product.Web.Controllers" } ); </code></pre> <p>Unfortunately when I go to an api url (in this case the example was <a href="http://www.product.com/api/Tables/" rel="nofollow">http://www.product.com/api/Tables/</a> (or even when I define an id), I get a HTTP 404 error. </p> <p><a href="http://www.product.com/Home/Index" rel="nofollow">http://www.product.com/Home/Index</a> works fine. </p> <p>Oddly enough I tried the <a href="http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx" rel="nofollow">routing debugger tool</a> and I still had issues. In fact I could never see the output of the debugger. <a href="http://www.product.com/Home/Index" rel="nofollow">http://www.product.com/Home/Index</a> and <a href="http://www.product.com/" rel="nofollow">http://www.product.com/</a> both show the view but everything api/* still shows 404. I have yet to see any output from the debugger.</p> <p>So is there anyway to get the desired effect?</p> <p>Edit: I noticed that my global.asax.cs file was in the <code>Product.Web</code> namespace. I changed it to be in the <code>Product</code> namespace and still no go.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload