Google News
logo
ASP.NET - Interview Questions
Explain how conventional routing works?
As the name suggests, conventional routing uses predefined conventions to match the incoming HTTP request to a controller’s action method. It handles the most general cases that a typical web application needs, but you can modify it to suit your specific needs.
 
For example, the Configure() method in the Startup.cs class contains the following code that sets up the conventional routing.
app.UseEndpoints(endpoints =>
{
  endpoints.MapControllerRoute(
      name: "default",
      pattern: "{controller=Home}/{action=Index}/{id?}");
});
This code creates a single route named ‘default’. The route template pattern ‘{controller=Home}/{action=Index}/{id?}’ is used to match an incoming URL such as /Posts/Archived/5 to the Archived(int id) action method on the PostsController, passing 5 for the id parameter. By default, the router uses the Index method on the HomeController. 
Advertisement