August 2017
Intermediate to advanced
330 pages
7h 26m
English
MapRoute is an extension method to add a route to IRouteBuilder with a specified name and template. A DefaultHandler needs to be added for route handling.
The following code shows how to define defaultHandler to be used with MapRoute:
var routeHandler = new RouteHandler(context =>
{
var data = context.GetRouteData().Values;
return context.Response.WriteAsync("Controller Name is " + data["controller"].ToString());
});
var routes = new RouteBuilder(app, routeHandler)
.MapRoute("packt", "{controller}/{action}")
.Build();
app.UseRouter(routes);
Read now
Unlock full access