ASP.NET Core Interview Question #216

How is ASP.NET Core hosted as a Windows Service?

Testing, Deployment & Hosting Senior Advanced

Quick Interview Answer

An ASP.NET Core application can run as a Windows Service when it needs to operate without an interactive user session and be managed by the Windows Service Control Manager.

Detailed Explanation

An ASP.NET Core application can run as a Windows Service when it needs to operate without an interactive user session and be managed by the Windows Service Control Manager.

The application uses the generic host and appropriate Windows-service hosting integration. Deployment must also configure the service account, file permissions, network access, recovery behavior, configuration, and secrets.

A Windows Service is useful for server-side processes, but a normal IIS-hosted web application may be more convenient when IIS features are required.

Code Example

var builder = WebApplication.CreateBuilder(args);

builder.Host.UseWindowsService();

var app = builder.Build();
app.MapGet("/", () => "Running");
app.Run();