Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my area routing failing for one controller but not another?
    primarykey
    data
    text
    <p>I have an MVC 4 site with the usual default routes defined (including an API route), plus an area for administration functions, which has its own route. The routing configuration looks like this:</p> <p>Default Route: </p> <pre><code>routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new[] { "MyProject.Controllers" } ); </code></pre> <p>Default API Route: </p> <pre><code>routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); </code></pre> <p>Admin Area Route (in the area registration code): </p> <pre><code>context.MapRoute( "Admin_default", "Admin/{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new[] { "MyProject.Areas.Admin.Controllers" } ); </code></pre> <p>Additionally, the admin area has it's own Layout page for the views. </p> <p>The routes for the main site all work correctly (including the HTTP routes for the API controllers), but the routes for the Admin area show some odd behaviour. Requests made to the home controller in the admin area succeed, whilst requests to other controllers in the admin area do not. The error that I get is</p> <pre><code>System.Web.HttpException: The controller for path '/admin/concerts' was not found or does not implement IController. </code></pre> <p>The interesting thing is that the stack trace associated with the exception contains code from the main Layout page, rather than the admin area's Layout page, which I think suggests that the request has been routed to the default route rather than the admin route. </p> <p>I've tried debugging the route configuration with Glimpse, but haven't had much luck, other than to confirm through a second medium that the route works correctly for the admin area's HomeController, but not for other controllers in the area. </p> <p><strong>Update:</strong></p> <p>I have the following relevant controllers defined:</p> <ul> <li>Default Route: <ul> <li><code>MyProject.Controllers.ConcertsController</code></li> <li><code>MyProject.Controllers.HomeController</code></li> <li>(Some others, not relevant here.)</li> </ul></li> <li>Default HTTP Route: <ul> <li><code>MyProject.Controllers.Api.ConcertsController</code> only</li> </ul></li> <li>Admin Area Route: <ul> <li><code>MyProject.Areas.Admin.Controllers.ConcertsController</code>; and</li> <li><code>MyProject.Areas.Admin.Controllers.HomeController</code> only</li> </ul></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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