Facebook Week – Day 4

Despite all the frustrations, yesterday was pretty productive. I knocked off the new game features in the morning and spent all afternoon (and evening) learning more about the Facebook API. ASP.NET, Facebook quirks, and IIS bugs made most of the day pretty unpleasant, but by last night everything was working as expected.

The big bug that was at the root of it all was this one. With IIS 5 you can’t POST to a default document. The webserver returns a 405 error instead of calling the document.  The bug is fixed in IIS 6, but you can’t actually install IIS 6… it comes with Windows Server 2003, so that fix is worthless to me on my XP Professional development machine.

This is a real problem for Facebook apps because Facebook puts anything after the application’s name on the end of the callback URL when loading the page.  So if the callback URL for your app “MurderMystery” is “http://somedomain.com/fbcallback.aspx” and you go to the canvas page “http://apps.facebook.com/MurderMystery/SuspectDetails.aspx” it actually calls the callback at “http://somedomain.com/fbcallback.aspxSuspectDetails.aspx”. That’s obviously not going to work.  The usual solution is to set “http://somedomain.com/” as the callback URL instead and let the webserver use the default document if you aren’t loading a specific canvas page. This IIS bug means that you must have an actual document name in your callback URL to accept POST requests.

No problem, I thought!  I’ll just go download a copy of ISAPI_Rewrite and use URL rewriting to work around the bug. That involved an hour or so of downloading, installing, and reading. I’m not much of a web programmer, so I wasn’t really familiar with URL rewriting. Once I figured out how it worked, my rewriting rules ended up being pretty simple.  I have a rule for the default page (to directly work around the IIS bug) and another for each sub-page. This has the happy side-effect of cleaning up URLs by stripping out the “.aspx?mysteryId=” gunk from every URL.

Unfortunately ASP.NET didn’t automatically grok my rewritten URLs. ASP.NET puts a form around every page so it can handle postbacks, and that form has the page’s actual document written into it.  I came up with a hack that got it all working using HttpContext.RewritePath(). It’s not pretty, and makes all kinds of assumptions about the URLs people will be hitting the page from, but it works.  If only the hack didn’t make me feel so dirty…

When I finished up last night I had multiple pages up and running in the app and was navigating between them. The most important of those pages is the one where you actually play the game, and right now that page is empty. Today’s task is to re-implement my game’s UI in FBML. The HTML version is about 300 lines, and all the back-end code will work just fine, so I think I can get that done today.

I’m using FBML instead of an IFrame so that I don’t have to deal with fetching and serving all the images and Facebook profile info myself. It also gives me access to useful controls like the multiple-friend invitation UI. It causes some problems for ASP.NET (controls that use Javascript don’t work, which includes LinkButton) but I think it’s worth the trade-off.  The result will be that the app will be more tightly integrated with Facebook.

Today I hope to accomplish:

  • Get the game-playing canvas page completely working (but probably not pretty)
  • Get started on automatic game creation

If today goes well I’ll probably put the game up sometime tomorrow in a rough form so other people can play it.

~Joe


5 Responses to “Facebook Week – Day 4”

  1. Tim replied on :

    “http://somedomain.com/fbcallback.aspxSuspectDetails.aspx”

    Not obvious why this won’t work – can’t you have the webserver redirect?

  2. Tim wrote on :

    Maybe reading everything before commenting is a good idea.

  3. Paul wrote on :

    Hi Joe,

    Would you mind sharing the Rewrite Rule you used to get around the IIS POST problem? Nothing I try seems to work!

    Thanks,

    Paul

  4. ned replied on :

    I would also be interested in learning about your hack approach. I’m running into a similar problem, where I need to find a way to handle postbacks in my FBML facebook app.

  5. Joe commented on :

    Unfortunately I don’t actually remember what the hack was. Sorry!

Leave a Reply