What are the differences between app.UseRouting() and app.UseMvcWithDefaultRoute()?

Viewed 1068

As I'm trying to understand them, what are the differences between app.UseRouting() and app.UseMvcWithDefaultRoute()?

2 Answers

Probably this link might help you. Basically

  1. UseMvcWithDefaultRoute() exists since .Net core 1.0
  2. UseRouting() is added in .Net Core 3.0 which has added more functionalities to handle custom routes.

I mainly use first approach with mostly razor pages. You can check "Endpoint routing differences from earlier versions of routing" in given link for more information. So, the final decision is whether you want to use Basic or Advanced Endpoint Routing

UseRouting is an advanced method. It just matches request to an endpoint. This is usually followed by useEndpoints() which actually executes matched endpoint. It doesn't necessarily indicate relation between routing and MVC.

UseMvcWithDefaultRoute takes care of everything. It is actually a convenience method for :

app.UseMvc(routes =>
{
   routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});

So it's strictly about MVC, also it follows the default routing(e.g. api/students/1). Nothing advanced.

Related