2

I have deployed an MVC3 and WCF web service as a single application. Both work as expected. GET and POST requests work perfectly, but the PUT and DELETE requests return 404 errors. These work fine locally. Initially it was requesting a username/password for PUT/DELETE requests.

Here is my WebServer config from my web.config file

    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <modules runAllManagedModulesForAllRequests="true">
            <remove name="WebDAVModule" />
        </modules>
        <handlers>
            <remove name="WebDAVModule" />
        </handlers>     
        <security>
          <authorization>
            <remove users="*" roles="" verbs="" />
            <add accessType="Allow" users="*" 
                            verbs="GET,HEAD,POST,DEBUG,PUT,DELETE" />
          </authorization>
        </security>             
    </system.webServer>

Here are my PUT and DELETE methods:

    [OperationContract]
    [WebInvoke(UriTemplate = "{id}", Method = "PUT")]
    public MyResource Put(MyResource updatedResource, int id)
    {
        MyResource existingResource = Database.GetResourceById(id);
        existingResource.Name = updatedResource.Name;
        Database.SaveResource(existingResource);

        return existingResource;
    }

    [OperationContract]
    [WebInvoke(UriTemplate = "{id}", Method = "DELETE")]
    public MyResource Delete(int id)
    {
        MyResource sampleResource = Database.DeleteResourceById(id);
        return sampleResource;
    }

My set up:

  • .NET 4.0
  • MVC3
  • IIS 7.0

Note: I am on a shared hosting plan, therefore do not have direct access to IIS7.0 a so I need to make changes via the web.config file.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 1
    I'm not sure how you can do this in a shared host, check [this](http://geekswithblogs.net/michelotti/archive/2011/05/28/resolve-404-in-iis-express-for-put-and-delete-verbs.aspx) out – MilkyWayJoe Jul 10 '12 at 23:10

1 Answers1

0

Enable Tracing on your service and see why you get a 404 error when you try for a PUT or DELETE action.

Rajesh
  • 7,766
  • 5
  • 22
  • 35
  • I've enabled tracing and implemented my own logging. It outputs confirmation messages when I call GET and POST methods, but it doesn't even acknowledge (nothing in trace file) that the PUT or DELETE methods were called. It's as if the calls are being blocked before they reach the web service. – user1157841 Jan 31 '12 at 07:17