In one of my projects where we are using the Content Delivery API from Episerver, we also have some custom logic in the templates for some Ajax posting.
This will respond with a 405 error with the message HTTP verb used to access this page is not allowed.
This might not be best practise to shoot XHR requests to the same request and manage the response in the same code that also handles the HTML rendering, but that is how it was build back then.
Looking into the binaries, I managed to find that this is caused by something in the EPiServer.ContentApi.Cms.dll binary.
When content is Routed the method ContentApiRouteService.ShouldRouteRequest is used to check whether or not this request should be rewritten to use the ContentDelivery API instead.
The default implementation of ContentApiRouteService checks whether the Accept Header contains “application/json”. Which is the case for of our current implementation.
With rewritten I mean that instead of the normal request destination which usually is your WebForms ASPX template or MVC Controller, the request should be routed to the ContentDelivery API at /api/episerver/v2.0/.
As we are depending on the request to reach our template, we need to disable this. The best way I could find is to override the ContentApiRouteService .ShouldRouteRequest method.
I replaced it with a method that just returned false. I never want the request to be routed to the ContentDelivery API. When I use the ContentDelivery API, I use the endpoint found at /api/episerver/v2.0.
Personally I think this is a case where Episerver disturbs our default rendering and I would prefer that
1) the ContentDelivery routing for requests with Accept Header “application/json” is an opt-in configuration as it is interfering with our
2) or that the routing is configurable so that I can opt-out without having to write code that overrides the default behaviour