Skip to main content

Kestrel-and-Hosting

Kestrel Server

What it is

The built-in, cross-platform web server for ASP.NET Core.

Main role

  • Listens for HTTP requests
  • Hosts and runs the ASP.NET Core app
  • Handles request/response processing

Capabilities

  • Supports HTTP/1.1, HTTP/2, HTTPS
  • High-performance and lightweight

Use case

  • Perfect for development
  • Can be used in production behind a reverse proxy

Key idea: Kestrel runs your app, but doesn't handle enterprise concerns well on its own.

Reverse Proxy Server

What it is

A server that sits in front of Kestrel and forwards requests.

Common examples

  • Nginx
  • Apache
  • IIS

Main responsibilities

  • Load balancing
  • SSL/TLS termination
  • Caching
  • Security (rate limiting, filtering, IP rules)

Use case

  • Production environments
  • Protects and enhances Kestrel

Key idea: Reverse proxy = security + scalability + performance.

How They Work Together

Client → Reverse Proxy → Kestrel → ASP.NET Core app
  • Kestrel focuses on app logic
  • Reverse proxy handles infrastructure concerns

ASP.NET Core Startup Logs

These logs come from Microsoft.Hosting.Lifetime and show the app lifecycle.

Now listening on

Shows the URL and port where Kestrel is accepting requests.

Example: http://localhost:5117

Application started

  • Confirms the app started successfully
  • Indicates how to shut it down (Ctrl + C)

Hosting environment

Shows the current environment:

  • Development / Staging / Production

Affects logging, error pages, and configuration.

Content root path

  • Base directory for the app's files
  • Used for static files, views, and configs

Why it matters: Helps verify startup status and troubleshoot configuration issues.


launchSettings.json

Purpose

  • Controls how the app runs in development
  • Used by Visual Studio / dotnet run
  • Not used in production

Main Sections

$schema

  • Enables validation and IntelliSense

iisSettings

  • Applies only to IIS Express
  • Controls:
    • Windows authentication
    • Anonymous authentication
    • IIS Express URLs and SSL

profiles

Defines different launch modes.

Project (http) profile

  • Runs via dotnet run
  • Configures:
    • Application URL
    • Environment variables
    • Auto browser launch
  • Common for local development

IIS Express profile

  • Runs via IIS Express
  • Mimics IIS behavior locally

Key Environment Variable

ASPNETCORE_ENVIRONMENT

  • Controls config files, logging, and error handling
  • Usually Development locally

One-Sentence Interview Version 🚀

Kestrel is the lightweight web server that hosts ASP.NET Core applications, while a reverse proxy like Nginx or IIS sits in front of it in production to handle SSL, load balancing, and security. Startup logs show the app lifecycle, and launchSettings.json controls how the app runs locally during development.