Reputation: 61
Context: Current system has a custom WebDav HttpHandler in place that handles file upload, editing etc. And website is WebFrom based. And the new WebAPI will be built on top of that.
Using the Asp.Net provided example project. Integration works fine except on all WebForms and WebAPI methods except the WebDav gets broken.
Issue: After registering the WebAPI in global.asax, the HTTP PUT request always got sent to WebAPI routing and WebDav's PUT request won’t have a match and get the 404 response (exception?).
According to this [article][1] it looks like HTTPRouting is different from MVC Routing. The HttpConfiguration.Routes does not have ignore() routes.
Goal to achieve: PUT requests are able to be distinguished and get sent to WebAPI or WebDav handler accordingly. For instance: Any request requests that does not match the WebAPI route pattern will be passed along the pipeline to the handlers instead of getting the exception response.
WebDav put request looks like this, which is virtualized as well:
PUT /dav/{USERID}/{AUTH_TOKEN}/{PRAMS}/{PATHINFO}2.png
--Edits
Exception from routing engine. What I'm looking for is a way to passthrough the request when no controller were found, let other handlers/modules in the IIS pipeline to handle the request instead of throw out error response.
Response generate by the WebAPI and it does not passed onto the CustomWebDavHandler:
[HttpException]: The controller for path {my WebDav virtual path} was not found or does not implement IController. at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Upvotes: 3
Views: 2641
Reputation: 61
Ok, my colleagues and I have figured this out...
The order of registration of the RouteConfig.cs and WebApiConfig.cs (those two files can be found in asp.net's example) matters..
In the global.asax, it was:
WebApiConfig.Register(GlobalConfiguration.Configuration);
RouteConfig.RegisterRoutes(RouteTable.Routes);
so that the WebApi routes gets in to IIS first. Which there's no ignore method in the route collection.
But, by register the RouteConfig first, where you do have the ignore method, then the dav request can be ignored and passthrough into handlers.
RouteConfig.RegisterRoutes(RouteTable.Routes);
WebApiConfig.Register(GlobalConfiguration.Configuration);
Upvotes: 3
Reputation: 21
can you try HttpMethod Constraint on the route http://msdn.microsoft.com/en-us/library/system.web.routing.route.constraints.aspx
Upvotes: 1