Host.md - brainchildservices/curriculum GitHub Wiki

SLIDE-1

Host

SLIDE-2

On startup, an ASP.NET Core app builds a host. The host encapsulates all of the app's resources, such as:

  • An HTTP server implementation
  • Middleware components
  • Logging
  • Dependency injection (DI) services
  • Configuration

SLIDE-3

There are two different hosts:

  • .NET Generic Host
  • ASP.NET Core Web Host

The .NET Generic Host is recommended. The ASP.NET Core Web Host is available only for backwards compatibility.

The following example creates a .NET Generic Host:

  public class Program
  {
      public static void Main(string[] args)
      {
          CreateHostBuilder(args).Build().Run();
      }

      public static IHostBuilder CreateHostBuilder(string[] args) =>
          Host.CreateDefaultBuilder(args)
              .ConfigureWebHostDefaults(webBuilder =>
              {
                  webBuilder.UseStartup<Startup>();
              });
  }

SLIDE-4

  • The CreateDefaultBuilder and ConfigureWebHostDefaults methods configure a host with a set of default options, such as:

    • Use Kestrel as the web server and enable IIS integration.
    • Load configuration from appsettings.json, appsettings.{Environment Name}.json, environment variables, command line arguments, and other configuration sources.
    • Send logging output to the console and debug providers.
  • ASP.NET Core provides the following server implementations:

    • Kestrel is a cross-platform web server. Kestrel is often run in a reverse proxy configuration using IIS. In ASP.NET Core 2.0 or later, Kestrel can be run as a public-facing edge server exposed directly to the Internet.
    • IIS HTTP Server is a server for Windows that uses IIS. With this server, the ASP.NET Core app and IIS run in the same process.
    • HTTP.sys is a server for Windows that isn't used with IIS.

SLIDE-5

Kestrel

Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the web server that's included and enabled by default in ASP.NET Core project templates.

Kestrel supports the following scenarios:

  • HTTPS
  • HTTP/2 (except on macOS†)
  • Opaque upgrade used to enable WebSockets
  • Unix sockets for high performance behind Nginx
  • †HTTP/2 will be supported on macOS in a future release.

Kestrel is supported on all platforms and versions that .NET Core supports.

SLIDE-5(DOWNWARDS)

Kestrel is an open source, cross platform, light weight and a default webserver used for Asp.Net Core applications. Asp.Net Core applications run Kestrel webserver as in-process server to handle web request. Kestrel webserver is based on async I/O library called libuv primarily developed for Node.js.

By default, all Asp.Net core project templates include Kestrel webserver when we create new Asp.Net Core Projects. As said before, Kestrel is a very light weight webserver that does not have every advanced features of webservers like IIS, Nginx, Apache, etc has. Due to its lightweight nature, Kestrel provides better request processing performance to Asp.Net Core applications. Some features of Kestrel,

  • Kestrel does not support multiple applications sharing same port similar to IIS where applications are differentiated by host header value.

  • Kestrel is cross platform, runs in Windows, LINUX and Mac.

  • Kestrel webserver supports SSL.

Let’s understand why there is a new webserver called Kestrel when we already have a feature-rich and most used webserver IIS.

⚠️ **GitHub.com Fallback** ⚠️