0

Given a PhoneCallListController in /Areas/Contacts/Controllers

And using a pretty standard ControllerFactory

protected override IController GetControllerInstance(System.Web.Routing.RequestContext, requestContext, System.Type controllerType)
{
  if (controllerType == null) return base.GetControllerInstance(requestContext, controllerType);
  return (IController) ObjectFactory.GetInstance(controllerType);
}

When making a request to http://localhost:2663/PhoneCallList

The controllerType passed in is base = {Name = "PhoneCallListController" FullName = "MyApp.Web.Areas.Contacts.Controllers.PhoneCallListController"

instead of the null that I was expecting. I would expect a 404 to occur, but the runtime is happily serving up an instance of this controller, but then failing because The view 'Index' or its master was not found... (which makes sense).

By contrast when making a request to http://localhost:2663/AControllerThatDoesntExsit, I get a null passed in (as expected) and end up with a 404 (also as expected).

Do I have something configured incorrectly? Or is there anything in the requestContext I should look at to make sure that the controller and the area in the request info match?

Thanks!

Joe
  • 5,389
  • 7
  • 41
  • 63
  • 1
    You're experiencing the standard functionality of the controller factory, see this question for a fix http://stackoverflow.com/questions/18455401/not-including-area-name-in-url-results-in-the-view-index-or-its-master-was-no/18456960 – Brent Mannering Dec 10 '14 at 22:21

2 Answers2

1

It`s possible that your RouteConfig class has a rule like this:

routes.MapRoute(
    name: "Default",
    url: "{controller}"
);
0

This is standard ASP.NET MVC behavior. The default action for a controller is the Index() method.

See Adding a Controller.

See this article for instructions on modifying the default action.

Community
  • 1
  • 1
Peter Gluck
  • 8,168
  • 1
  • 38
  • 37
  • I would expect this if my controller was in the default controllers namespace/folder, but it's buried in /Areas. – Joe Dec 10 '14 at 21:39