Reputation: 5497
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!
Upvotes: 0
Views: 102
Reputation: 8236
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.
Upvotes: 0
Reputation: 19
It`s possible that your RouteConfig class has a rule like this:
routes.MapRoute(
name: "Default",
url: "{controller}"
);
Upvotes: 1