in case i making a application using mvc and i am using asp.net core 8 or 9 should i use the UseRouting() with the UseEndPoints() or i can use the UseRouting() only and the top level route registration ot i should not use both and just register the route at the top level
note: "please i want a pref answer that makes me understand the concept i am begginer at this topic"
Loading

mina shakerPosted Jan 28, 2025, 5:38 AM
@Tuhin Paul but when i use he UseEnpoint in my application the visual Stoudio give me warrning the `ASP0014: Suggest using top level route registrations`
Tuhin PaulPosted Jan 27, 2025, 4:02 PM
So, to clarify
UseRouting()sets up the routing infrastructure.UseEndpoints()is where you define how requests should be handled, like linking routes to MVC controllers.Example of both being used in an MVC app
Why you need both -
UseRouting()is necessary because it sets up the routing system and ensures that the application knows how to route the requests to the right endpoint.UseEndpoints()is needed to actually map those routes to specific handlers (like your controllers and actions in an MVC app).Can you use just one?
No, you can’t just use
UseRouting()or justUseEndpoints()alone. You need both becauseUseRouting()establishes the infrastructure to check incoming requests, andUseEndpoints()is where you define what happens when a route is matched.Tuhin PaulPosted Jan 27, 2025, 3:58 PM
In ASP.NET Core (version 8 or 9),
UseRouting()andUseEndpoints()work together to define how incoming requests are routed and handled in your application. To answer your question, you typically need to use bothUseRouting()andUseEndpoints()when working with MVC.UseRouting():UseEndpoints():UseRouting()to define how to handle the matched route.Sangeetha SPosted Jan 27, 2025, 4:56 AM
In ASP.NET Core 8, using
UseRouting()andUseEndpoints()is generally recommended for setting up routing in your web application. Here’s a brief overview of their purposes and usage:UseRouting()
UseRouting()in your application's middleware pipeline. It must be placed before any middleware that relies on routing, such as authorization or endpoint execution.UseEndpoints()
UseEndpoints()afterUseRouting(). This is where you configure the actual endpoints in your application.Example Usage
Here’s a simple example of how to use
UseRouting()andUseEndpoints()in theConfiguremethod of yourStartup.csfile: