Routing in ASP.NET Core

Routing is the process of mapping incoming HTTP requests to the code that handles them. In ASP.NET Core, routing is a fundamental part of building web APIs and MVC applications.

Key Concepts

Getting Started

C#
JSON
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();

var app = builder.Build();

app.UseRouting();

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

app.Run();
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

Try it Now

Use the interactive console below to test a simple route pattern.