Attribute-based routing
Until now, we have used convention-based routing. In convention-based routing, we define the routing templates (which are just parameterized strings) in a centralized place these are applicable to all the available controllers. The problem with convention-based routing is that, if we want to define different URL patterns for different controllers, we need to define a custom URL pattern that is common to all the controllers. This makes things difficult.
There is another option for configuring the routing engine-attribute-based routing. In attribute-based routing, instead of configuring all the routing in a centralized location, the configuration will happen at the controller level.
Let us see an example of attribute-based routing.
First, let us remove the convention-based routing that we created earlier in the Configure
method in theĀ startup.cs
class file:
public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); ...