Detect AJAX postback in Global.asax
Recently working on a page hit logging scenario that, for reasons
having to do with URL rewriting, needed to have the logging code
executed in the Application.BeginRequest event of Global.ajax. The
application relies heavily on ASP.Net Ajax, and I needed a was to ferret
out the AJAX requests and not log them.
Ordinarily, in the page
lifecycle, this would be accomplished by using Page.IsAsync. In this
case, I needed to perform the logging prior to the page code being
invoked.
To determine the whether the request was generated by AJAX, I used the following code:
VB.Net
Request.Headers("X-MicrosoftAjax") = "Delta=true"
C#
Request.Headers["X-MicrosoftAjax"] = "Delta=true";