Sobes.tech
Junior — Middle

What is the difference between UseRouting and UseEndpoints functions in ASP.NET Core routing configuration?

sobes.tech AI

Answer from AI

In ASP.NET Core, UseRouting and UseEndpoints are two stages of routing configuration that serve different functions.

  • UseRouting adds middleware to the pipeline that analyzes the request URL and matches it with registered routes. At this stage, the route is determined, but the request is not yet processed.

  • UseEndpoints is middleware that is called after UseRouting and is responsible for executing endpoints, such as controllers, Razor Pages, or other handlers that match the found route.

Example of usage in Startup.Configure:

app.UseRouting();

app.UseAuthorization(); // for example, authorization between routing and endpoints

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
});

Thus, UseRouting finds the route, and UseEndpoints executes the request processing for that route.

What is the difference between UseRouting and… - sobes.tech