0

After reading several similar questions and trying their solution, none worked for me.

I have this controller with the same route for get, post and put. The 3 work perfectly locally, but deployed on the server, PUT returns me a 404.

Here's the code for the controller actions. All obfuscated because, its code I'm developing for a client

[Route("objects/")]
[Route("objects/{token}/")]
[Route("controller/objects/")]
[Route("controller/objects/{token}/")]
[ActionName("objects")]
[HttpGet()]
public List<Object> Objects(string token)
{
    // Works perfectly, both local and deployed
}
[Route("objects/")]
[Route("objects/{token}/")]
[Route("controller/objects/")]
[Route("controller/objects/{token}/")]
[ActionName("objects")]
[HttpPost()]
public string InsertObjects([FromUri]string token, [FromBody]Newtonsoft.Json.Linq.JObject obj)
{
     // Returns a 500, but at least its called. Not used for the moment
}
[Route("objects/")]
[Route("controller/objects/")]
[ActionName("objects")]
[HttpPut()]
public string RemoveObject([FromBody]Newtonsoft.Json.Linq.JObject obj)
{
    // Returns a 404 deployed on server. Works perfectly locally
    // If you wonder why put instead of delete for a remove action, its because we don't delete from the db, just set a field value to false
}

I have been reading that, it might be that the PUT handler is not on the config, but this is the current handler

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

As you can see, verb is set to *, which means it should also consider PUT and DELETE, right?

CJLopez
  • 5,495
  • 2
  • 18
  • 30
  • 2
    Disable the WebDAV module. – CodeCaster Jun 02 '16 at 14:09
  • 1
    Wow, didn't saw that one! thanks, will try this, and report back, will take some time, as this servers is managed by the client and the client's it personal must do this – CJLopez Jun 02 '16 at 14:19
  • In 99% of cases, this is the culprit. If not, please show what other things you have tried. "ASP.NET WebApi 404" gives a _lot_ of Stack Overflow hits on Google already. – CodeCaster Jun 02 '16 at 14:27
  • 1
    Well, in the end, this wasn't the solution. After getting a little talk with the admins of the server, I found out that the firewall was the one not letting `PUT` and `DELETE` methods go through. So I had to write my own message handler and do a Method Override with the header `X-HTTP-Method-Override`. So I'm sending a `POST`with this header when a `PUT` is due. More about this strategy on this [link](http://www.hanselman.com/blog/HTTPPUTOrDELETENotAllowedUseXHTTPMethodOverrideForYourRESTServiceWithASPNETWebAPI.aspx) – CJLopez Jun 02 '16 at 20:26

0 Answers0