Tuesday, July 16, 2013

Detect AJAX postback in Global.asax


 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";

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More