is the UseRouting() or the UseEndpoints() resposible for selecting the controller , as far as i know the the latest is resposible for invoking the action after the match is done using the first
Loading
is the UseRouting() or the UseEndpoints() resposible for selecting the controller , as far as i know the the latest is resposible for invoking the action after the match is done using the first
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit MohantyPosted Nov 19, 2024, 5:24 AM
UseRouting():This function includes routing middleware in pipeline.
Use Endpoints(): End the routing cycle by invoking the matched endpoint: for example an action of a controller.
In summary, the UseRouting() selects the endpoint; for example, it may be a controller and an action depending on routed data. UseEndpoints() will run the endpoint-on that execute the controller action or handler.
Benjamin GabrielPosted Nov 19, 2024, 7:37 AM
UseRouting()is responsible for matching the incoming request to a route and identifying the appropriate controller and action based on the route table, but it does not execute the action.UseEndpoints()comes after and is responsible for executing the matched endpoint, such as invoking the action method in the controller. Together,UseRouting()sets up the match, andUseEndpoints()completes the request processing by executing it.Jignesh KumarPosted Nov 19, 2024, 5:51 AM
Hello Mina,
You need to configure these methods in the
Startupclass of your project using the code below:Jayraj ChhayaPosted Nov 19, 2024, 5:47 AM
Hi @mina shaker,
In ASP.NET Core, the middleware responsible for selecting the controller is
UseRouting(). This middleware analyzes the incoming request and matches it to the appropriate route defined in your application. It sets up the routing context, which includes determining the controller and action to be invoked based on the URL.Once the routing is complete,
UseEndpoints()comes into play. This middleware is responsible for executing the matched endpoint, which includes invoking the action method of the selected controller. In summary,UseRouting()is tasked with selecting the controller, whileUseEndpoints()handles the invocation of the action after the match is established.Here’s a simple example of how these middlewares are typically configured in the
Startup.csfile:This configuration ensures that the routing and endpoint execution processes are correctly set up in your ASP.NET Core application.