Conventional routing is defined once and applies to all controllers. It is best for small to medium enterprise websites.
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
Attribute routing gives you 100% fine-grained control over your URLs. It is the gold standard for REST APIs.
[Route("api/v1/[controller]")]
public class OrdersController : ControllerBase {
[HttpGet("{id:int}")]
public IActionResult GetOrder(int id) { /* ... */ }
}
A senior architect doesn't just use {id:int}. They create custom constraints for business requirements (e.g., verifying a valid product code format).
public class ProductCodeConstraint : IRouteConstraint {
public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection) {
var value = values[routeKey]?.ToString();
return Regex.IsMatch(value, "^PC-[0-9]{5}$");
}
}
Endpoint routing was introduced in .NET Core 3.0 to allow routing to happen early in the pipeline. For a 12-year architect, understanding how to use RewriteOptions to handle 301 redirects across multiple domains is the difference between a successful migration and a SEO disaster.