Map

The Map method helps when you want to connect multiple instances of middleware. To do this, Map calls another request delegate. Look at the following screenshot for the signature of this method:

Signature of Map method

Look at the following code:

public void Configure(IApplicationBuilder app)
{
app.UseMvc();
app.Map("/testroute", TestRouteHandler);
async Task RequestDelegate(HttpContext context)
{
await context.Response.WriteAsync("This ends the request or
short circuit request.");
}
app.Run(RequestDelegate);
}

In this code, I added a Map that just maps <url>/testroute. Following this is the same Run method that we discussed previously. TestRoutehandler is a private method. Look at the following code:

private static void  TestRouteHandler(IApplicationBuilder app) 
{
async Task Handler(HttpContext context)
{
await context.Response.WriteAsync("This is called from testroute.
" + "This ends the request or short circuit request.");
}
app.Run(Handler);
}

Before app.Run(Handler); is a normal delegate. Now, run the code and look at the results. They should be similar to the following screenshot:

You can see that the root of the web application is showing the string that is mentioned in the Run delegate method. You will get the output shown in the following screenshot: