X-HTTP-Method-Override gives NotFound (404) on ASP.NET Web API

前端 未结 2 1090
长发绾君心
长发绾君心 2021-01-18 02:35

I am trying to implement HTTP method override following the steps described here. Basically, I am creating a DelegatingHandler, similar to the following, and adding it as a

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-18 03:03

    I have tried to reproduce your error but I wasn't able to. Here, you can download my simple project with your message handler: https://dl.dropbox.com/u/20568014/WebApplication6.zip

    I would like to point out that message handlers run before the action selection logic is performed. So, in your case, probably something else causes the problem and I think you should look at your other message handlers, your message handler's registration code, etc because the problem occurs due to the fact that your message handler never runs.

    Also, I think your IRouteConstraint implementation, GetHttpMethodConstraint, looks suspicious to me.

    Here is my registration code for the message handler:

    protected void Application_Start(object sender, EventArgs e) {
    
        var config = GlobalConfiguration.Configuration;
        config.Routes.MapHttpRoute(
            "DefaultHttpRoute",
            "api/{controller}/{id}",
            new { id = RouteParameter.Optional }
        );
    
        config.MessageHandlers.Add(new MethodOverrideHandler());
    }
    

提交回复
热议问题