Posts

Showing posts with the label asp.net-web-api2

WebAPI routing does not work

Image
Clash Royale CLAN TAG #URR8PPP WebAPI routing does not work I have WebApiConfig public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } } Web API controller: [RoutePrefix("api/Trip")] public class TripApiController : ApiController { [Route("SaveRouting")] [HttpPost] public async Task<HttpResponseMessage> SaveRouting(string points, int tripId, decimal totalMileage) { // ...... return Request.CreateResponse(HttpStatusCode.OK); } and call from jquery: $.post("/api/trip/SaveRouting", { points: JSON.stringify(arrayStops), tripId: $("#hdTripId").val(), totalMileage: tMiles }, fu...

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; ...