When should you use attribute routing versus convention-based routing?

ASP.NET MVC Routing Intermediate 2–3 Yrs3–5 Yrs Conceptual 1 min read

Quick Answer

Use attribute routing ([Route("api/products/{id:int}")]) for Web APIs and any irregular URLs — the route sits with the action, is explicit, and supports constraints. Use convention routing ({controller}/{action}/{id?}) for large server-rendered MVC sites where most URLs follow the same pattern. You can mix both.

Attribute routing puts the route right on the action, so it's explicit and it's what I use for APIs — it's actually required with [ApiController] — and for any URL that doesn't fit a neat pattern. Convention routing defines the URL shape once, centrally, as {controller}/{action}/{id?}, and that's nice for a large MVC site where nearly every URL follows that template and I don't want to repeat a route on every action. There's no reason not to mix them — convention for the bulk, attributes for the special cases.

  • Attribute routing is required for [ApiController].
  • Convention routing keeps a big site's URLs uniform with one central definition; less noise on each action.
  • Attribute routing wins when URLs vary (/blog/2026/03/my-post, /checkout/step-2) or you want versioning in the path.
  • Route constraints ({id:int}, {slug:regex(...)}, {page:min(1)}) work in both but read naturally in attributes.