Routing constraints are part of the templating routing system of ASP.NET Core. They provide a way for us to match a route with a parameter type or a set of values, like so:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("default", "{controller}/{action}/{id:guid?}");
});
In this case, our route template will match all the https://myhostname/mycontroller/myaction calls and all the calls that present a valid Guid as an id parameter, for example, https://myhostname/mycontroller/myaction/4e10de48-9590-4531-9805-799167d58a44. The {id:guid?} expression gives us two pieces of information about constraints: first, the parameter must have the guid type, and secondly, it is specified as optional using the ? character. ASP.NET Core provides a rich set of built-in routing constraints such as min and max values, regular expressions...