Tutorials ASP.NET Core MVC Mastery

Conventional vs Attribute Routing

On this page

Professional ASP.NET Core Routing architectures

Section 1: Conventional (MapControllerRoute)

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?}");
                        

Section 2: Attribute Routing (The API standard)

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) { /* ... */ }
}
                        

Section 3: Custom Constraint Mastery

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}$");
    }
}
                        

Architect Insight: Endpoint Routing & URL Rewriting

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.

Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

ASP.NET Core MVC Mastery
Course syllabus
1. Core Framework
MODULE 1: INTRODUCTION & ENVIRONMENT SETUP
2. View Engine
MODULE 2: .NET CORE FUNDAMENTALS
MODULE 3: ASP.NET CORE BASICS
MODULE 4: MVC FUNDAMENTALS
MODULE 5: DATA PASSING TECHNIQUES
MODULE 6: ROUTING
MODULE 7: VIEWS & UI
MODULE 8: ACTION RESULTS
MODULE 9: HTML HELPERS
MODULE 10: TAG HELPERS
MODULE 11: MODEL BINDING
MODULE 12: VALIDATION
MODULE 13: STATE MANAGEMENT
MODULE 14: FILTERS & SECURITY
MODULE 15: ENTITY FRAMEWORK CORE (DEEP DIVE)
MODULE 16: DESIGN PATTERNS
MODULE 17: FILE HANDLING
MODULE 18: ADVANCED ASP.NET CORE
MODULE 19: PERFORMANCE & BEST PRACTICES
MODULE 20: RAZOR PAGES (BONUS)
MODULE 21: REAL-WORLD PROJECTS (🔥 MUST DO)
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details