Posts

Showing posts with the label asp.net-web-api-routing

DelegatingHandlers not executing when routes not defined

Image
Clash Royale CLAN TAG #URR8PPP DelegatingHandlers not executing when routes not defined I am working on a WebAPI 2 project which currently uses attribute-based routing exclusively, to the point that there are no routes defined in registration, and everything is working as expected. However, I am now adding a DelegatingHandler to provide a heartbeat that I can ping with a HEAD request: DelegatingHandler public class HeartbeatMessagingHandler : DelegatingHandler { protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (IsHeartbeat(request)) { if (request.Method == HttpMethod.Head) { var response = new HttpResponseMessage(HttpStatusCode.NoContent) { Content = new StringContent(string.Empty) }; var task = new TaskCompletionSource<HttpResponseMessage>(); task.SetResult(response); return task.Task; ...