ASP.NET Core › Endpoint Metadata, Route Constraints & Templates

How would you debug why a specific request isn't matching the route you expect it to, using ASP.NET Core's routing diagnostics?

Advanced

Answer

Enabling debug-level logging for the Microsoft.AspNetCore.Routing category reveals detailed information about route matching attempts, including which candidate routes were considered and why they were rejected (constraint mismatch, missing required parameter) -- combined with inspecting HttpContext.GetEndpoint() to confirm exactly which endpoint (if any) actually matched, this is the primary diagnostic path for tracking down unexpected routing behavior.
// appsettings.Development.json
{
  "Logging": {
    "LogLevel": {
      "Microsoft.AspNetCore.Routing": "Debug"
    }
  }
}
// Logs will show candidate routes evaluated and why each was accepted/rejected
Real-world example A developer confused why a request to /products/42 was unexpectedly hitting a catch-all NotFound handler instead of the expected /products/{id:int} route enables routing debug logging, immediately revealing a typo in the route constraint syntax that was silently causing it to never match.

Common follow-ups: What routing-related information does HttpContext.GetEndpoint() expose for debugging?;How would you write an automated test specifically verifying route matching behavior?