So far, we’ve spent a great amount of time discussing what happens in the middleware pipeline. We’ve talked about how requests get passed from the server to the pipeline and then from one delegate to the next. We’ve also mentioned how requests can arrive at the end of the pipeline, get routed appropriately, and then a response is returned. Now, let’s dive a little deeper into how requests are routed.
Configure() method starts, an important routing component,
UseRouting(), must be called to compare the HTTP request with the available endpoints and decide which is the best match. Prior to the
UseRouting() component being executed, the endpoint for all HTTP requests is null and it continues being null unless an appropriate match is found. If we were requesting the Contact page,
UseRouting() would take our HTTP request and match it with the
It is important to mention that the application would fail without the
UseRouting() component. Also, a null endpoint or failed routing usually ends with displaying an error page. Although
UseRouting() does not take the HTTP request to its final destination, it does provide the address of where the request needs to go in order for the proper response to be issued.
Take a look at the diagram. The
UseRouting() component compares the HTTP request with a list of the available destinations. Once it finds a match, the middleware pipeline continues processing.