Skip to content

ASP.NET Maintenance Mode ​

Blocks traffic while a maintenance window is active, with a service that turns the window on and off and a file on disk holding the state, so a window survives process restarts without a database table or an external coordinator.

It ships no endpoint for controlling maintenance mode, because how that is exposed and who may call it is an application decision.

Categories ​

  • Configuration — maintenance path, default message, expiry behavior, redirects, and the allow lists.
  • Extensions — service and middleware registration.
  • Services — the DI contract used to read, enable, and disable maintenance mode.
  • Records — the request, state, and response records.

Quick Example ​

csharp
using AlmightyShogun.AspNet.Core;
using AlmightyShogun.AspNet.MaintenanceMode;

builder.Services
    .AddHttpErrorResponseWriter()
    .AddMaintenanceMode(builder.Configuration);

WebApplication app = builder.Build();

app.UseMaintenanceMode();
csharp
using AlmightyShogun.AspNet.MaintenanceMode;

public sealed class DeploymentMaintenance(
    IMaintenanceService maintenanceService
)
{
    public async Task StartAsync()
    {
        var request = new MaintenanceRequest
        {
            Message = "Upgrading the database. Back shortly.",
            EndsAt = DateTimeOffset.UtcNow.AddMinutes(30),
            AutoDisableWhenExpired = true,
            AllowedPaths = ["/health"],
            AllowedPathPrefixes = ["/ops"]
        };

        await maintenanceService.EnableAsync(request);
    }

    public async Task FinishAsync()
        => await maintenanceService.DisableAsync();
}
json
{
    "Maintenance": {
        "MaintenancePath": "/maintenance",
        "DefaultMessage": "The application is temporarily unavailable.",
        "AllowedPaths": ["/health"]
    }
}

All packages are released under the MIT License.