This is where the actual determination to execute a specific controller motion is created. UseEndpoints evaluates the route information supplied by UseRouting and invokes the right controller and motion technique.
Attribute routes may also be coupled with inheritance. That is potent coupled with token replacement. Token substitution also applies to route names described by attribute routes.
Let's take a look at a couple of examples of how the Default route maps URLs to controller steps. Think about which you enter the following URL into your browser address bar:
Allow’s Consider the two roots from earlier mentioned. The first route would be the default route by using a default controller and motion and the second route has the static segment InternalBlog in front of the controller. What transpires When the user enters “/InternalBlog/Posts/Display screen”?
Attribute routes guidance a similar inline syntax as common routes to specify optional parameters, default values, and constraints.
The web site/lookup/ subject matter route has greater precedence, by default, mainly because it's a lot more distinct. Using typical routing, the developer is responsible for putting routes in the specified get.
Attribute routing employs a list of characteristics to map actions directly to route templates. The next StartUp.Configure code is regular for the Relaxation API and is used in the following sample:
Route templates applied to an action that begin with / or ~/ Do not get combined with route routing in asp.net mvc templates applied to the controller. The next illustration matches a set of URL paths just like the default route.
The route values for controller and motion normally seem in that template. This is effective since the URLs matched by routing adhere to some Conference.
Routing tries to use the values in ambient values to fill in facts that was not provided when generating a URL. Look at a route like a / b / c / d with ambient values a = Alice, b = Bob, c = Carol, d = David :
This is due to the default route has specified a parameter called id but no id parameter was available while in the Controller approach. If we put a breakpoint during the Controller process, We're going to see that the ‘class’ parameter is coming in as null.
This is useful for sustaining reliable habits and minimizing the need to specify each and every parameter inside the URL explicitly.
The GetInt2Product motion incorporates id in the template, but won't constrain id to values that could be converted to an integer. A GET ask for to /api/test2/int2/abc: Matches this route.
The standard default route handles routes far more succinctly. Nevertheless, attribute routing lets and needs specific control of which route templates use to every action.