Get started with ASP.NET Core: architecture, application types, project setup, Kestrel hosting, and your first Web API.
ASP.NET Core is Microsoft open-source, cross-platform web framework for building modern APIs, web apps, and real-time services. Rebuilt from scratch on .NET Core, it runs on Windows, Linux, and macOS, delivers best-in-class throughput in TechEmpower benchmarks, and ships with built-in dependency injection, a modular middleware pipeline, and flexible hosting on Kestrel.
ASP.NET Core is a cross-platform, high-performance, open-source framework for
building modern, cloud-enabled, Internet-connected applications. It is a complete
rewrite of ASP.NET that runs on Windows, Linux, and macOS.
Cross-platform development
High performance
Built-in dependency injection
Modular HTTP pipeline
Cloud-ready configuration
Open source
Learn about ASP.NET Core vs ASP.NET Framework.
Learn about Application Types.
RESTful services for mobile apps, SPAs, and microservices
Server-rendered web apps with the Model-View-Controller pattern
Page-focused scenarios with simpler organization
Interactive web UIs using C# instead of JavaScript
1┌──────────────────────┬─────────────────────────────┐
2│ Feature │ ASP.NET Core │
3├──────────────────────┼─────────────────────────────┤
4│ Platform │ Windows, Linux, macOS │
5│ Performance │ Very high (Kestrel server) │
6│ Dependency Injection │ Built-in │
7│ Configuration │ Multiple providers │
8│ Hosting │ Self-hosted or IIS/Nginx │
9│ Updates │ NuGet packages │
10│ Open Source │ Yes (MIT License) │
11└──────────────────────┴─────────────────────────────┘Setting up ASP.NET Core requires .NET SDK and an IDE:
┌──────────────────────┬─────────────────────────────┐
│ Feature │ ASP.NET Core │
├──────────────────────┼─────────────────────────────┤
│ Platform │ Windows, Linux, macOS │
│ Performance │ Very high (Kestrel server) │
│ Dependency Injection │ Built-in │
│ Configuration │ Multiple providers │
│ Hosting │ Self-hosted or IIS/Nginx │
│ Updates │ NuGet packages │
│ Open Source │ Yes (MIT License) │
└──────────────────────┴─────────────────────────────┘
1# Windows (using winget)
2winget install Microsoft.DotNet.SDK.8
3
4# macOS (using Homebrew)
5brew install --cask dotnet-sdk
6
7# Linux (Ubuntu)
8sudo apt-get update
9sudo apt-get install -y dotnet-sdk-8.0
10
11# Verify installation
12dotnet --version
13# Output: 8.0.1001# Create a new Web API project
2dotnet new webapi -n MyApi -o MyApi
3
4# Create a minimal API project
5dotnet new web -n MinimalApi -o MinimalApi
6
7# Create an MVC project
8dotnet new mvc -n MyMvcApp -o MyMvcApp
9
10# List all available templates
11dotnet new list
12
13# Common templates:
14# webapi - ASP.NET Core Web API
15# web - ASP.NET Core Empty (Minimal)
16# mvc - ASP.NET Core MVC
17# razor - ASP.NET Core Razor Pages
18# blazorserver - Blazor Server App
19# blazorwasm - Blazor WebAssembly App1# Navigate to project directory
2cd MyApi
3
4# Restore dependencies
5dotnet restore
6
7# Build the project
8dotnet build
9
10# Run the application
11dotnet run
12
13# Run with hot reload (development)
14dotnet watch run
15
16# Run with specific environment
17ASPNETCORE_ENVIRONMENT=Development dotnet run
18
19# Output:
20# info: Microsoft.Hosting.Lifetime[14]
21# Now listening on: https://localhost:5001
22# Now listening on: http://localhost:5000
23# info: Microsoft.Hosting.Lifetime[0]
24# Application started. Press Ctrl+C to shut down.An ASP.NET Core project has a defined structure with Program.cs as the entry point:
winget install Microsoft.DotNet.SDK.8
brew install --cask dotnet-sdk
sudo apt-get update
sudo apt-get install -y dotnet-sdk-8.0
dotnet --version
1MyApi/
2├── Controllers/ # API Controllers
3│ └── WeatherForecastController.cs
4├── Properties/
5│ └── launchSettings.json # Development settings
6├── appsettings.json # Application configuration
7├── appsettings.Development.json
8├── Program.cs # Application entry point
9└── MyApi.csproj # Project file1// Program.cs - Modern .NET 8 style
2var builder = WebApplication.CreateBuilder(args);
3
4// Add services to the container
5builder.Services.AddControllers();
6builder.Services.AddEndpointsApiExplorer();
7builder.Services.AddSwaggerGen();
8
9var app = builder.Build();
10
11// Configure the HTTP request pipeline
12if (app.Environment.IsDevelopment())
13{
14 app.UseSwagger();
15 app.UseSwaggerUI();
16}
17
18app.UseHttpsRedirection();
19app.UseAuthorization();
20app.MapControllers();
21
22app.Run();1using Microsoft.AspNetCore.Mvc;
2
3namespace MyApi.Controllers;
4
5[ApiController]
6[Route("api/[controller]")]
7public class WeatherForecastController : ControllerBase
8{
9 private static readonly string[] Summaries = new[]
10 {
11 "Freezing", "Bracing", "Chilly", "Cool", "Mild",
12 "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
13 };
14
15 private readonly ILogger<WeatherForecastController> _logger;
16
17 public WeatherForecastController(ILogger<WeatherForecastController> logger)
18 {
19 _logger = logger;
20 }
21
22 [HttpGet]
23 public IEnumerable<WeatherForecast> Get()
24 {
25 _logger.LogInformation("Getting weather forecast");
26
27 return Enumerable.Range(1, 5).Select(index => new WeatherForecast
28 {
29 Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
30 TemperatureC = Random.Shared.Next(-20, 55),
31 Summary = Summaries[Random.Shared.Next(Summaries.Length)]
32 })
33 .ToArray();
34 }
35}
36
37public record WeatherForecast
38{
39 public DateOnly Date { get; init; }
40 public int TemperatureC { get; init; }
41 public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
42 public string? Summary { get; init; }
43}ASP.NET Core apps run on Kestrel, a cross-platform web server that can be used
directly or behind a reverse proxy like IIS, Nginx, or Apache.
Learn about Kestrel Web Server.
Learn about Reverse Proxy Configuration.
Learn about Environment Configuration.
1// Configure Kestrel in Program.cs
2var builder = WebApplication.CreateBuilder(args);
3
4builder.WebHost.ConfigureKestrel(serverOptions =>
5{
6 serverOptions.Listen(IPAddress.Any, 5000); // HTTP
7 serverOptions.Listen(IPAddress.Any, 5001, listenOptions =>
8 {
9 listenOptions.UseHttps(); // HTTPS
10 });
11
12 // Configure limits
13 serverOptions.Limits.MaxConcurrentConnections = 100;
14 serverOptions.Limits.MaxRequestBodySize = 10 * 1024 * 1024; // 10MB
15 serverOptions.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
16});
17
18var app = builder.Build();
19app.Run();1// Configure forwarded headers for reverse proxy
2builder.Services.Configure<ForwardedHeadersOptions>(options =>
3{
4 options.ForwardedHeaders =
5 ForwardedHeaders.XForwardedFor |
6 ForwardedHeaders.XForwardedProto;
7});
8
9var app = builder.Build();
10
11app.UseForwardedHeaders();
12
13// Nginx configuration example:
14# /etc/nginx/sites-available/myapp
15# server {
16# listen 80;
17# server_name myapp.com;
18#
19# location / {
20# proxy_pass http://localhost:5000;
21# proxy_http_version 1.1;
22# proxy_set_header Upgrade $http_upgrade;
23# proxy_set_header Connection keep-alive;
24# proxy_set_header Host $host;
25# proxy_cache_bypass $http_upgrade;
26# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
27# proxy_set_header X-Forwarded-Proto $scheme;
28# }
29# }1// appsettings.json
2{
3 "Logging": {
4 "LogLevel": {
5 "Default": "Information",
6 "Microsoft.AspNetCore": "Warning"
7 }
8 },
9 "AllowedHosts": "*",
10 "ConnectionStrings": {
11 "DefaultConnection": "Server=localhost;Database=MyDb;..."
12 }
13}
14
15// appsettings.Development.json
16{
17 "Logging": {
18 "LogLevel": {
19 "Default": "Debug",
20 "Microsoft.AspNetCore": "Information"
21 }
22 }
23}
24
25// Access configuration in code
26var connectionString = builder.Configuration
27 .GetConnectionString("DefaultConnection");
28
29// Check environment
30if (app.Environment.IsDevelopment())
31{
32 app.UseDeveloperExceptionPage();
33}
34else
35{
36 app.UseExceptionHandler("/Error");
37 app.UseHsts();
38}Your progress is saved in this browser, on this device only.