What is Hosting in ASP.NET Core? See Example

Hosting in ASP.NET Core refers to how the application runs and handles HTTP requests. ASP.NET Core apps can be hosted on Kestrel (cross-platform web server), IIS, Nginx, or Apache, making them flexible for different environments. Hosting also manages the lifetime of the app and configuration of services.

Key Features:

  • Supports multiple web servers (Kestrel, IIS, Nginx, Apache)
  • Configures services and middleware at startup
  • Manages app lifetime and environment
  • Supports cross-platform deployment
  • Flexible and extensible for cloud or on-premises hosting

Example:
Basic hosting in Program.cs:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello ASP.NET Core Hosting!");

app.Run();

ASP.NET Core hosting ensures apps are efficient, scalable, and deployable across multiple platforms.

Citations:

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *