Routing constraints

ASP.NET Core, either as an MVC or a web API application, supports both attribute and centralized routing mechanism. The routes can either be directly set on the controller and actions using the Route attribute, or by creating and mapping all the routes in one place.

We have seen that different route templates can be created with or without route parameters. When route templates have parameters in them, it helps to build excellent routing patterns. But the presence of route parameters can cause issues too; let's see an example for this:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { var routeBuilder = new RouteBuilder(app); routeBuilder.MapGet("employee/{id}", context ...

Get Mastering ASP.NET Web API now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.