Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 837
MrJahanbin Avatar asked Sep 13 '25 09:09

MrJahanbin


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

like image 171
phonemyatt Avatar answered Sep 14 '25 22:09

phonemyatt


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.

like image 31
Gaurav Kalele Avatar answered Sep 14 '25 22:09

Gaurav Kalele