I've read countless other threads about this particular routing error message, but none seem to pertain to my situation. Here's a dumbed-down version of my code:
Request
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage requestOne)
{
var reqClone = await requestOne.Clone();
var responseOne = await base.SendAsync(requestOne, default(CancellationToken));
var responseTwo = await base.SendAsync(reqClone, default(CancellationToken));
return responseTwo;
}
Controller Sample
/// <summary>
/// Create an oRecord.
/// </summary>
/// <param name="cKey">key</param>
/// <param name="oRecord">record</param>
/// <param name="ct">cancellation token</param>
[Route(RouteDefinitions.ExampleRoutes.TestRoute)]
[Authorize]
[HttpPost]
public async Task<IHttpActionResult> Create(string cKey, [FromBody] OResource oRecord, CancellationToken ct)
{
return something;
}
I have a controller setup for Get, Detetes, Puts, and Posts. No matter what HTTP request we call, the first request will reach the controller and do the expected actions, but the second request will immediately fail in System.Web.Http with a
404: No HTTP resource was found that matches the request http://request/com/api/v1/example
I'll also mention that the same thing happens if we do two different requests (i.e. a Postand then a Get) in the same call to the same server.
My controller routing seems to be set up fine because we get the first call to succeed.
Does anyone have pointers as to where to look? Could something be happening between the two calls that would modify the routing data?
Thank you in advance for the help!
UPDATE
Fixed but root cause unknown!
I found a fix to the issue and I half-understand the root cause. I noticed that the RouteData for my two requests were different. See below:
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage requestOne)
{
var reqClone = await requestOne.Clone();
IHttpRouteData routeData = requestOne.GetRouteData();
IHttpRouteData clonedRouteData = reqClone.GetRouteData();
var responseOne = await base.SendAsync(requestOne, default(CancellationToken));
IHttpRouteData routeDataAfterRequestOne = requestOne.GetRouteData();
IHttpRouteData clonedRouteDataAfterRequestOne = reqClone.GetRouteData();
var responseTwo = await base.SendAsync(reqClone, default(CancellationToken));
return responseTwo;
}
I found that if I ran the above code, both routeData and clonedRouteData would be of type RouteCollectionRouteData. However, after running the first request, routeDataAfterRequestOne and clonedRouteDataAfterRequestOne both would return type HttpRouteData.
I'm still not sure why the RouteData changed, especially for the cloned request, but it did. I fixed my issue by implementing the following:
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage requestOne)
{
IHttpRouteData routeData = requestOne.GetRouteData();
var reqClone = await requestOne.Clone();
var responseOne = await base.SendAsync(requestOne, default(CancellationToken));
reqClone.setRouteData(routeData);
var responseTwo = await base.SendAsync(reqClone, default(CancellationToken));
return responseTwo;
}
If anyone knows why the RouteData may have been updated for both requests, please let me know. I'd like to have a better understanding of what happened. Thanks!