September 26th, 2006

Canonical AJAX almost stumps Ian

Today I was consulted to debug a rather nasty bit of AJAX - a paging script that lives within Community Server. The problem appeared spontaneously on a bunch of sites where we applied a new ISAPI Rewrite rule: one that finds any instances of "default.aspx" and scrubs them out via redirection. Why scrub out the default file names? To produce canonical URLs. The idea of canonical URLs is pretty well established: we don't ever want two URLs to deliver the same content. Ideally, valid variations of a URL should be redirected to the canonical with a 301. So for example a request for "/dir/foo/default.aspx" is 301 redirected to "/dir/foo/". The shorter URL is nicer; most people agree. .NET Postback causes problems with that. For some unknown reason Microsoft decided that the "action" for Postback would be the SCRIPT_NAME, not the URL. And AFAIK it's not something we can control. Well even though my URL is "/dir/foo/", the SCRIPT_NAME is "/dir/foo/default.aspx", the Postback page adds "default.aspx" and there ain't nothin' I can do 'bout it. The redirection happens, the Post is gone, and things get busted. I like GET. GET is easy, I totally dig QueryStrings, and GET works so nicely in AJAX applications, XML feeds, etc. In Community Server, the AJAX component that does the paging makes an AJAX POST request, not a GET. The HttpXmlRequest that goes out requests a URL that, if redirected, no longer works. It was really difficult to figure that out! For one thing - when an AJAX HttpXmlRequest is going out, how can you track it? It doesn't show up in HttpWatch. You can't see it in the Javascript Console. The browser does this XML thing, and doesn't make a peep. No built-in browser panel or dialog in my arsenal would show me what URL was being requested. I don't feel good about that. Not just because it cripples AJAX debugging, (imagine doing this when you don't have write permission to add alerts to the javascript) but because it's my freakin' browser and I don't appreciate it doing secret things in the background that I can't - should I choose to - watch in real time. Understandably when I'm dragging the map in Google Local, I don't want to be pestered with alerts. But in those instances where I do want to be notified, can't I opt in to that? Maybe there's a Firefox plugin that does it... you can get a FF plugin to do anything these days. So it turns out (after stepping into the code and carefully tracing my way through heaps of object-oriented javascript) that the URL for this particular AJAX request was done with POST. And it's the POST data that contained the page number being requested. So now I know that in .NET applications I can't scrub the default file name out to make a nice short canonical URL. In our application of Community Server, the canonical URLs include the filename. So it goes. Everywhere else I abhor having "default.aspx" in the URL. In .NET applications like Community Server, it not only stays but achieves canonized status.

Filed under Uncategorized

One Response to “Canonical AJAX almost stumps Ian”

  1. Jarhead Says:

    Hey Ian,
    Firebug for Firefox shows you HTTPRequests as they go out. It exposes AJAX activity, and debugging becomes much easier.

    There are tools to do this for IE too, you just have to look for them. You knob.

Leave a Reply