Using ASP.NET AJAX in an FBML application?

Feb 6, 2008 at 4:46 PM
I've found a few critical issues working with AJAX in an FBML application.

1) Facebook appends a123456789_ to all objects and functions, including built-in types like Function and Array and Object (which MS's implementation uses extensively). My initial reaction was that I could just redirect that (i.e., a123456789_Function = Function; but of course that doesn't work since the second function gets it appended anyway :)

2) Unless I'm missing something, Facebook doesn't seem to resolve relative urls for the script includes.

E.g., <script src="mylocalscript.js"/> becomes <script src=""></script>

When I look at the value of that static call, it's empty. If I put it in as a fully-qualified, absolute url, it loads fine. The issue with this is that the ASP.NET ScriptManager seems to render out relative urls by default, and I haven't figured out any way to change this behavior.

Is anyone using ASP.NET AJAX successfully in an FBML (not iframe) application?
Jul 2, 2008 at 5:54 PM
Seeing as this thread never got any action:
I've been playing with this recently, and wasn't able to get it to run either.  Facebook sandboxes the MicrosoftAjax.js javascript in a way that seems to spell doom as soon as a I put a ScriptManager on the page.  Anyone else have luck?
Jul 3, 2008 at 9:50 PM
I'll ask Terrence McGhee to come over to this thread. His app, Thugz Passion (excellent game, by the way), is using Facebook.NET and ASP.NET Ajax extensively.

Jul 3, 2008 at 11:40 PM
My app uses iframe (because I wanted to use my own javascript) so I'm afraid that I'm not much help on fbml apps.

However, I had planned to get more familiar with fbml and Ajax in the near future.

This codeproject article ( goes into *some* detail about fbml and Ajax (you have to get to the bottom of the article).

Maybe something can be gleaned from there?
Jul 8, 2008 at 2:50 AM
Edited Jul 8, 2008 at 2:51 AM
Just to update this thread with my explorations:

In general you can get non-ASP.NET pages to call to ASP.NET web services by including MicrosoftAjax.js in a script tag. However, this does not work with FBML pages because MicrosoftAjax attempts to add functions to base Javascript objects like Function, Date and Array.  Facebook expressly forbids this, and so sandboxes these calls with a hash like it does with all FBJS function names.  This causes MicrosoftAjax.js to misbehave -- it tries to call functions that never got bound to the base objects.

As the link provided by TMC suggests, one way to make this work is to make a Facebook Ajax ("Mock AJAX") call to an aspx page, which then renders into HTML. You take this HTML response, parse it as necessary, and act on it. The main downside of this approach is that you now need to figure out your own serialization protocol, whereas ASP.NET AJAX did the JSON serialization for you.
Jul 8, 2008 at 8:20 PM
Edited Jul 8, 2008 at 8:23 PM
I've rooted out the source of the problem. Due to Facebook’s Javascript security model, we are required to use Facebook’s own javascript Ajax object for making asynchronous calls – we cannot use typical ASP.NET means such as ScriptManager or by importing MicrosoftAjax.js. The Facebook Ajax object (docs here) only makes HTTP POSTs using application/x-www-form-urlencoded content headers. However, as far as we know, ASP.NET [WebMethod] Web Services will automatically reject any POSTs that are not of content-type application/json –described as a security feature on ScottGu’s blog here. Is there any way to get a Web Service (asmx) to respond to an application/x-www-form-urlencoded HTTP POST?