I understand for conventional routing, the request first hit mvcmiddleware, then the router will compare the request to the predefined templates.
if it find one that matches, the route values are extracted from the request and assigned to route parameters of the selected template. The controller and action route parameters is what is then used to find the route for the request.
Whilst on the other hand attribute routes urls are calculated at runtime and stored in a dictionary as a key value pair of url and an associated action, and when a request hits mvcmiddleware, it checks if the request url is a key in the dictionary and invokes the associated action.
But as the request hits mvcmiddleaware where we have both route types defined, which of the routers tends to handle the request first?
According to my understanding both conventional and attribute based routing use a middleware. I would assume that the routing rules evaluation follows the middleware registrations. So if the routing based middleware is configured first (UseRouting
) then its rules should be evaluated first.
In order to make sure, which one get evaluated first I would suggest to use a Route Debugger, like this, blog post. With this by calling the UseRouteDebugger
you would be able to see the resolved routing rule in the response header.