Consuming and Deploying ASP.NET WebApi Services – Gotchas!!

Last week I posted about how every web programmer should know about the RESTful nature of Web and start using Asp.NET MVC 4 Web Api to accomplish the same. The post was accompanied by a sample HTTP GET resource call to an ASP.NET Web Api controller action.

So, I believe you people have already started using WebApi; If not then this post may still help you as and when you start.

This post focuses on some of the issues I have encountered while developing using ASP.NET WebApi and the solutions to get around those issues.

Gotcha 1 –> PUT and DELETE request won’t work on IE10

This one caused quite a pain when I started using WebApi and discovered that PUT and DELETE request don’t work in IE10 (specifically in Windows 8 64-bit). I am not sure why it doesn’t work in the latest and greatest version of Internet Explorer, BUT that’s how it is. There is a workaround for this issue. We can add this tag inside the <head> tag of our Web page to make IE10 work like IE9.

<meta http-equiv=”X-UA-Compatiblecontent=”IE=EmulateIE9” >

You could add it to all your pages or on just the pages which make PUT or DELETE requests, your call. BUT it is something to keep in mind while developing with ASP.NET WebApi until MS comes up with a fix for this.

Gotcha 2 –> PUT and DELETE requests do NOT work once the application is deployed in IIS

When you start working with WebApi you’ll realize its awesome, very easy and all his honky dory as long as you are developing in VS and debugging your solution. BUT, once you deploy your WebApi application in IIS you run into problems and some if your WebApi calls do not work. Don’t be surprised as this is quite a common issue as IIS is by default not configured to serve PUT/DELETE requests.

    • Configuring IIS 7.5 for WebApi

         Sometimes the WebDav module installed in IIS 7/7.5 causes issues when a WebApi application is deployed in IIS. Not sure what the reason is, BUT the solution that worked for me was removing the WebDav module for my application. This is made possible by adding the below tag in your web.config file, which instructs IIS to not register the WebDav module for our application. The below tags have to be included inside the <system.webServer> tag in the application’s web.config.

<modules runAllManagedModulesForAllRequests=”true“>
<remove name=”WebDAVModule” />
</modules>
<handlers>
<remove name=”WebDAV” />
</handlers>

    • Configuring IIS 6 for WebApi

This one is a little tricky and has no proper explanation as to why it works. BUT we need to configure IIS6 for WebApi for our application to work consistently. The workaround has been sourced from Phil Haack’s post about using ASP.NET MVC on IIS 6. The post itself is very informative, BUT the part which we are interested in is at the bottom. So, I’m gonna put it out here for you guys :

  • Right click on your deployed application and select properties
  • In the properties windows, click Configuration to open the “Application Configuration” window.

application mappings

  • Get the path to the aspnet_isapi dll using the below method.

One easy way to find out is to find the .aspx extension in the list and double click it to bring up the mapping dialog.

extension mapping

Now you can copy the path in the Executable text box to your clipboard.

  • Now, onto the previous “Application Configuration” window. In the Wildcard application maps section, click the Insert… button.
  • This brings up the wildcard application mapping dialog. Enter the path to the aspnet_isapi.dll copied in the previous step.

wildcard extension mapping

Don’t forget to uncheck the Verify that file exists checkbox! This is one of the most common mistakes people make and can cause a headache if not done. It may cause the application to stop working completely.

So, that’s it. You should be good to go. Remember, everybody might not face these issues as their IISs might be configured correctly or they might be using the correct version of the correct browser already. BUT having knowledge about these Gotchas should come in handy.

If you have any questions or view regarding these, give me a shout in the comments section.