I have come across the following posts in SO where the users had same route template on different controllers. Currently the error message which we get is not clear which makes the debugging experience bad. We should provide a clearer message.
http://stackoverflow.com/questions/19956974/webapi-2-0-routes-not-matching-with-query-parameters
http://stackoverflow.com/questions/19914237/web-api-2-routing-attributes-work-in-one-controller-but-not-another
_Error message(404 response)_:
```
{"Message":"No HTTP resource was found that matches the request URI 'http://kcthinkpad:9095/api/values?email=foo'.","Mes
sageDetail":"No route providing a controller name was found to match request URI 'http://kcthinkpad:9095/api/values?emai
l=foo'"}
```
_Issue_:
The problem is with the following piece of code where if it finds that a reuqest matches different controller types, then we return a null after which the controller selectors thinks of doing coventional routing check which as expected would not work as conventional routes do not match attribute routes.
I think we should throw an error in this case?
```
internal static HttpControllerDescriptor GetDirectRouteController(this IHttpRouteData routeData)
{
CandidateAction[] candidates = routeData.GetDirectRouteCandidates();
if (candidates != null)
{
// Set the controller descriptor for the first action descriptor
Contract.Assert(candidates.Length > 0);
Contract.Assert(candidates[0].ActionDescriptor != null);
HttpControllerDescriptor controllerDescriptor = candidates[0].ActionDescriptor.ControllerDescriptor;
// Check that all other candidate action descriptors share the same controller descriptor
for (int i = 1; i < candidates.Length; i++)
{
if (candidates[i].ActionDescriptor.ControllerDescriptor != controllerDescriptor)
{
return null;
}
}
return controllerDescriptor;
}
return null;
}
```
__Attached__ a katana repro
Comments: Verified.
http://stackoverflow.com/questions/19956974/webapi-2-0-routes-not-matching-with-query-parameters
http://stackoverflow.com/questions/19914237/web-api-2-routing-attributes-work-in-one-controller-but-not-another
_Error message(404 response)_:
```
{"Message":"No HTTP resource was found that matches the request URI 'http://kcthinkpad:9095/api/values?email=foo'.","Mes
sageDetail":"No route providing a controller name was found to match request URI 'http://kcthinkpad:9095/api/values?emai
l=foo'"}
```
_Issue_:
The problem is with the following piece of code where if it finds that a reuqest matches different controller types, then we return a null after which the controller selectors thinks of doing coventional routing check which as expected would not work as conventional routes do not match attribute routes.
I think we should throw an error in this case?
```
internal static HttpControllerDescriptor GetDirectRouteController(this IHttpRouteData routeData)
{
CandidateAction[] candidates = routeData.GetDirectRouteCandidates();
if (candidates != null)
{
// Set the controller descriptor for the first action descriptor
Contract.Assert(candidates.Length > 0);
Contract.Assert(candidates[0].ActionDescriptor != null);
HttpControllerDescriptor controllerDescriptor = candidates[0].ActionDescriptor.ControllerDescriptor;
// Check that all other candidate action descriptors share the same controller descriptor
for (int i = 1; i < candidates.Length; i++)
{
if (candidates[i].ActionDescriptor.ControllerDescriptor != controllerDescriptor)
{
return null;
}
}
return controllerDescriptor;
}
return null;
}
```
__Attached__ a katana repro
Comments: Verified.