[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1711
  • Last Modified:

PUT & DELETE issues with IIS 7.5

Hey experts,

 I'm having an issue similar to the one in this link - http://forums.iis.net/p/1166025/1937842.aspx - It happened on one of our servers after upgrading Plesk from 10 to 11 (it's not happening on other servers running Plesk 10 or in a local environment). And the issue is PUT & DELETE HTTP verbs not working when trying to call REST APIs.

We have a site ourdomain.com that is calling REST APIs on restapi.ourdomain.com via an API Proxy (ourdomain.com/proxy/api/<api_call> ). However, the call is NOT going from the proxy to the restapi.ourdomain.com. The error code returned is 404 [Not Found] (a bit different than the ones in the link); and we have calls from other subdomains games.ourdomain.com (running flash swf) calling directly restapi.ourdomain.com that are working normally after the upgrade to Plesk 11. I verified that everything mentioned in the forums.iis link is already done on our server (or else it wouldn't have worked before on Plesk 10); but still it seems that the Plesk upgrade messed up with some flag or permission.

Any help on it would be super great (The server is running IIS 7.5 on Windows Server 2008 R2 on a VPS machine, and both ourdomain.com & restapi.ourdomain.com are running on .NET 4.0).
0
mte01
Asked:
mte01
  • 3
  • 2
1 Solution
 
mte01Author Commented:
I fixed this by disabling WebDAV in IIS (I didn't see before an option to disable WebDav - it was only being removed in web.config).
0
 
kdbatCommented:
Hi mte01,
what if I want to use WebDAV and RESTApi together?
Disabling the whole WebDAV is not an option for me.
0
 
mte01Author Commented:
>>kdbat

If you want to use both, I'm not sure what you can do in this case :)
0
 
kdbatCommented:
>>mte01
>>If you want to use both, I'm not sure what you can do in this case :)
WebDAV is installed, but for the site A it is deactivated and the site B has it activated.
I want to use PUT DELETE for a REST API (asp.net apicontroller), and added these verbs to be allowed in requests, but still get the 405 not allowed. MS website does not tell anything about deploying apicontroller websites to a production iis environment.
But when you use the IIS Express to run the rest api, it is working... but not on the IIS7.5 in production environment.
I guess it is not an issue to Plesk 11, because I get the same behavior on IIS7.5 that is not installed in a plesk environment.
0
 
kdbatCommented:
Hi,
I have found the ASP.Net solution for this, to have WebDAV running an still can have REST Apis with CRUD operations.

Original Post found at:
github.com

using System.Net.Http;

public class HttpMethodOverrideHandler : DelegatingHandler
{
   const string header = "X-Http-Method-Override";
   string[] methods = new string[] { "PUT", "DELETE" };
   protected override System.Threading.Tasks.Task<HttpResponseMessage> 
   SendAsync(HttpRequestMessage request, 
      System.Threading.CancellationToken cancellationToken)
   {
      if (request.Method == HttpMethod.Post &&
         request.Headers.Contains(header))
      {
         var realmethod = request.Headers.GetValues(header).FirstOrDefault();
         if (realmethod != null && methods.Contains(realmethod.ToUpperInvariant()))
         {
            request.Method = new HttpMethod(realmethod);
         }
      }
      return base.SendAsync(request, cancellationToken);
   }
}

Open in new window


and then add this in your Global.asax.cs file:

GlobalConfiguration.Configuration.MessageHandlers.Add(new HttpMethodOverrideHandler());

Open in new window


Then you can do your REST PUT and DELETE requests as (I am using amplify.js here):


amplify.request.define("restUpdate", "ajax", {
   url: "api/restapiurl",
   dataType: "json",
   type: "POST",
   contentType: "application/json; charset=UTF-8",
   beforeSend: function (xhr) {
      xhr.setRequestHeader("X-Http-Method-Override", "PUT"); // <= the magic header
      return true;
   }
});

var updateContactAmplify = function (callbacks, data) {
   return amplify.request({
      resourceId: 'restUpdate',
      data: data,
      success: callbacks.success,
      error: callbacks.error
   });
};

Open in new window

0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now