Class SharedHttpServerManager
Manages shared Kestrel server instances across multiple route contexts.
One server per (host, port) combination. Multiple consumers can register routes
on the same port. Supports dynamic route addition/removal at runtime.
public sealed class SharedHttpServerManager : IAsyncDisposable
Inheritance
Implements
Properties
Options
The process-wide host options this manager applies to every listener it opens.
public HttpHostingOptions Options { get; }
Methods
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or
public ValueTask DisposeAsync()
EnableWebSockets(string, int, TimeSpan?, bool, string?, string?)
Declares the listener on host:port for a transport that serves WebSocket
public void EnableWebSockets(string host, int port, TimeSpan? keepAliveInterval = null, bool ssl = false, string? sslCertPath = null, string? sslCertPassword = null)
EnsureStarted(string, int, CancellationToken)
Ensures the server for the given host:port is started.
public Task EnsureStarted(string host, int port, CancellationToken ct = default)
GetBaseUrl(string, int)
Gets the base URL for a server. Available after EnsureStarted.
public string? GetBaseUrl(string host, int port)
GetResolvedPrincipal(HttpContext)
Returns the principal the host resolved for this request (), or null.
public static ClaimsPrincipal? GetResolvedPrincipal(HttpContext context)
RegisterEndpoints(string, int, IServiceProvider, Action<IEndpointRouteBuilder>, bool, string?, string?)
Maps endpoints of a transport's own onto the listener on host:port, before
public EndpointRegistration RegisterEndpoints(string host, int port, IServiceProvider services, Action<IEndpointRouteBuilder> map, bool ssl = false, string? sslCertPath = null, string? sslCertPassword = null)
RegisterRoute(string, int, string, string?, Func<HttpContext, Task>, bool, string?, string?, RouteCorsOptions?, long, HttpProtocol, ClientCertificateMode?, Func<X509Certificate2, X509Chain?, SslPolicyErrors, bool>?, ConcurrencyLimitOptions?)
Registers a route handler on the shared server for the given host:port.
public RouteRegistration RegisterRoute(string host, int port, string pathTemplate, string? methods, Func<HttpContext, Task> handler, bool ssl = false, string? sslCertPath = null, string? sslCertPassword = null, RouteCorsOptions? corsOptions = null, long maxRequestBodySize = 0, HttpProtocol protocol = HttpProtocol.Http1And2, ClientCertificateMode? clientCertificateMode = null, Func<X509Certificate2, X509Chain?, SslPolicyErrors, bool>? clientCertificateValidation = null, ConcurrencyLimitOptions? concurrencyLimit = null)
StopIfEmpty(string, int, CancellationToken)
Stops the server for the given host:port if it has no remaining routes.
public Task StopIfEmpty(string host, int port, CancellationToken ct = default)
UnregisterRoute(RouteRegistration)
Unregisters a route. If no routes remain on the server, it will be stopped on next StopServer call.
public void UnregisterRoute(RouteRegistration registration)
Constructors
SharedHttpServerManager()
Creates a manager with default options: no trusted proxies, forwarded headers ignored.
SharedHttpServerManager(HttpHostingOptions?, ILogger?)
Creates a manager with host options and a logger for the failures that happen before any
SharedHttpServerManager(HttpHostingOptions?)
Creates a manager with explicit host options. Under DI the options arrive through