IIS5 216493 Issue

From Facebook Developer Wiki

Jump to: navigation, search

Problem

Facebook sends a POST request to the callback URL to get the inital canvas page. Developers on IIS5 suffer from bug [[1]] whereby POST requests to URLs ending in / (forward slash) returns a 405 error page. You cannot redirect round it as the POST request from facebook does not follow the redirect.

Solution

Modify your web.config file adding a new httpModule inside the <system.web> section

  <httpModules>
	<add type="namespacePath.ClassName" name="ClassName"/>
  </httpModules>

Create the class at the correct location for the namespace, where ClassName is the name of the class, for example PathRewriter

using System;
using System.Web;

namespace namespacePath {
	public class PathRewriter : IHttpModule {
		void IHttpModule.Init(HttpApplication context) { context.BeginRequest += RewriteRequest; }
		void IHttpModule.Dispose() { }

		public void RewriteRequest(object sender, EventArgs args) {
			HttpApplication application = (HttpApplication) sender;
			string rawURI = application.Request.RawUrl;
			if (rawURI == "/") {
				rawURI = "/default.aspx";
			}
                        application.Context.RewritePath(rawURI);
		}
	}
}


  1. Finally goto Internet Information Services
  2. Find your website
  3. right click, properties.
  4. Click on the Home Directory tab
  5. then click Configuration
  6. The Mappings tab should be selected, if not select it.
  7. Click Add
  8. Browse
  9. Find the aspnet_isapi.dll file in the v2.0.50727 framework folder
  10. Extension = .*
  11. Verbs = All Verbs
  12. Script Engine = ticked
  13. Check that file exists = unticked
  14. Click the textbox where the executable is, the Ok button should be clickable now (another microsoft bug)

When you run the site now, what happens is that all requests run through this PathMapper class, if the url is the root url it appends default.aspx before it hits IIS proper bypassing the bug.

You can extend this class to have much nicer paths, so that instead of http://apps.facebook.com/appname/Dostuff.aspx you can make http://apps.facebook.com/appname/Dostuff/ resolve the the same location etc etc

reference