---
title: "What is Routing in ASP.NET Core and its types?"  
description: "What is Routing in ASP.NET Core and its types?"  
author: "Anubhav Sharma"  
published: 2026-03-29  
updated: 2026-03-30  
canonical: https://www.mindstick.com/forum/162069/what-is-routing-in-asp-dot-net-core-and-its-types  
category: "asp.net core"  
tags: ["asp.net core"]  
reading_time: 3 minutes  

---

# What is Routing in ASP.NET Core and its types?

**What is [Routing in ASP.NET](https://www.mindstick.com/forum/157462/what-is-routing-in-asp-dot-net-core) Core and its types?**

## Replies

### Reply by Ravi Vishwakarma

> **Maps an incoming HTTP request (URL) to a specific controller action or endpoint.**

## Simple Understanding

When a user hits:

```plaintext
/article/details/10
```

[Routing](https://www.mindstick.com/articles/11998/attribute-routing-in-asp-dot-net-mvc) decides:

- Which **Controller**
- Which **Action Method**
- What **parameters**

## How Routing Works

Flow:

```plaintext
URL → Routing Engine → Controller → Action → Response
```

Example:

```plaintext
/article/details/10
```

Mapped to:

```plaintext
ArticleController → Details(int id = 10)
```

## Types of Routing in ASP.NET Core

There are mainly **2 types**:

## 1. Conventional Routing

Defined centrally in `Program.cs`

### Example:

```cs
app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");
```

### How it works:

- URL follows a pattern
- Controller & action inferred automatically

### Example URL:

```plaintext
/Home/About
```

Calls:

```plaintext
HomeController → About()
```

### Pros:

- Simple
- Good for standard apps

### Cons:

- Less control for complex APIs

## 2. Attribute Routing

Defined directly on controllers/actions using attributes

### Example:

```plaintext
[Route("article")]
public class ArticleController : Controller
{
    [Route("details/{id}")]
    public IActionResult Details(int id)
    {
        return View();
    }
}
```

### URL:

```plaintext
/article/details/10
```

### Shortcut:

```plaintext
[HttpGet("article/details/{id}")]
```

### Pros:

- More control
- Cleaner for APIs
- Flexible URLs

### Cons:

- Can get messy if overused

## 3. Endpoint Routing (Modern Approach)

Introduced in [ASP.NET Core](https://www.mindstick.com/articles/12946/get-started-with-asp-dot-net-core-mvc-and-visual-studio) 3+

Configured in:

```plaintext
app.MapControllers();
```

Works with:

- Attribute routing
- Minimal APIs

## 4. Minimal API Routing (Advanced)

Used in lightweight APIs:

```plaintext
app.MapGet("/hello", () => "Hello World");
```

## Route Parameters

### Example:

```plaintext
{controller}/{action}/{id?}
```

- `controller` → required
- `action` → required
- `id?` → optional

## Route Constraints

Restrict parameter types:

```plaintext
[Route("product/{id:int}")]
```

## Default Values

```plaintext
{controller=Home}/{action=Index}/{id?}
```

## Routing vs URL Rewriting

- **Routing** → maps URL to code
- **URL Rewriting** → modifies URL before routing

### Best approach:

- Use **Attribute Routing** for APIs
- Use **Conventional Routing** for UI pages

## Common Mistakes

### 1. Conflicting routes

- Two routes match same URL → error

### 2. Missing `app.MapControllers()`

- Routes won’t work

### 3. Overusing hardcoded routes

- Not maintainable

## Real Example (Best Practice)

```plaintext
[Route("api/articles")]
public class ArticleController : Controller
{
    [HttpGet("")]
    public IActionResult GetAll() {}

    [HttpGet("{id:int}")]
    public IActionResult GetById(int id) {}
}
```

## Final Definition

> Routing in ASP.NET Core is the system that **connects URLs to the right code (controller/action)** so the application can respond correctly.


---

Original Source: https://www.mindstick.com/forum/162069/what-is-routing-in-asp-dot-net-core-and-its-types

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
