Processing boomerang beacons in ASP.NET

A prerequisite to enabling boomerang web beacons for your web pages, as discussed in the previous post, is providing a web server component that expects incoming GET Requests for the boomerang.gif and understands how to respond to those Requests. Let’s see how to handle the boomerang.gif GET Requests in IIS and ASP.NET.

An excellent way to add support for boomerang web beacons is to provide a class that supports the IHttpModule interface, which works so long as you are running IIS 7.0 or later in integrated mode. In integrated mode, which is also known as integrated pipeline mode, IIS raises a pre-defined sequence of events for each and every web request. The IIS feature was called the integrated pipeline mode because it extended the original ASP.NET event pipeline, introduced in ASP.NET version 1, to apply to the processing of all Http Requests, beginning with IIS version 7. The IIS integrated pipeline provides “a single place to implement, configure, monitor and support server features such as single module and handler mapping configuration, single custom errors configuration, single url authorization configuration,” in the words of Mike Voldarsky, who was a Program Manager for the Microsoft Web development team at the time. (In addition, Mike published an excellent technical article discussing the capabilities of the on the subject in MSDN Magazine subsequent to the product’s release.)

So, to process boomerang beacons, you could instantiate a BoomerangBeacon class that supports the IHttpModule interface that adds an event handler for the IIS pipeline BeginRequest event:

public class BoomerangBeacon : IHttpModule

{

 public BoomerangBeacon()

{            }

 public void Dispose()

{             }

public void Init (HttpApplication application)

{

application.BeginRequest += (new EventHandler(this.Application_BeginRequest));

}

}

LISTING 5. DEFINING A BOOMERANGBEACON CLASS THAT SUPPORTS THE IHTTPMODULE INTERFACE TO INTERCEPT THE BOOMERANG WEB BEACON AS SOON AS IT IS PROCESSED IN THE IIS INTEGRATED PIPELINE.

IIS raises the BeginRequest event as soon as a GET Request is received and is queued for processing in the pipeline. Next, provide an Application_BeginRequest method to intercept the boomerang beacon GET Request as soon as the, something along the lines of the following:

private void Application_BeginRequest(Object source, EventArgs e)

{

// Create HttpApplication and HttpContext objects to access

         // request and response properties.

HttpApplication application = (HttpApplication)source;

HttpContext context = application.Context;

 

string beaconUrl = GetBeaconUrl();  // Helper routine to set beacon url

string filePath = context.Request.FilePath;

string fileExtension = VirtualPathUtility.GetExtension(filePath);

if (fileExtension.Equals(“.gif”))

{

if (filePath.Equals(“/” + beaconUrl) || filePath.Contains(beaconUrl))

{

  …   // Process the beacon parms

application.Response.End();

}

}

}

LISTING 6. A BEGINREQUEST EVENT HANDLER THAT INTERCEPTS THE BOOMERANG WEB BEACON GET REQUEST IN ORDER TO PROCESS ITS QUERYSTRING PARMS.

This example calls a Helper routine, GetBeaconUrl(), to retrieve the name of the beacon Url from a web.config application setting. After processing the parms attached to the boomerang beacon GET Request, the BeginRequest event handler calls the End() method on the ASP.NET Response object that flushes the web beacon GET Request from the pipeline and terminates any further processing of the boomerang beacon. Calling Response.End() returns an empty HTTP Response message to the requestor with an HTTP status code of 200 – which is the “OK” return code – to the web browser that issued the Request.

NameValueCollection parms = context.Request.QueryString;

LISTING 7. ASP.NET PROVIDES ACCESS TO THE REQUEST QUERYSTRING VIA THE BUILT-IN HTTPCONTEXT OBJECT.
The key, of course, is processing the web beacon Query string parms that contain the measurement data from the web client. ASP.NET automatically generates a QueryString property that parses the GET Request query string and returns a NameValueCollection

HttpRequest request = context.Request;
string Browser = request.Browser.Type;
string Platform = request.Browser.Platform;
string HttpMethod = request.HttpMethod;

LISTING 8. IDENTIFYING THE HTTP METHOD, THE BROWSER TYPE (I.E., IE, CHROME), AND THE OS PLATFORM WHERE THE REQUEST ORIGINATED.

making it a relatively simple matter of looping through the parms collection and pulling out the measurements, exactly how Yahoo’s boomerang howto.js script I referenced earlier does. Your ASP.NET code that processes the web beacon can also pull the HttpMethod, Browser.Type and Browser.Platform directly from the Request object, as illustrated in Listing 8.

In addition, your IHttpModule class can also process the IIS ServerVariables collection to pull the identifying web client IP address and TCP Port assignment. These IIS web server variables are returned as strings, but it is not too much trouble to transform them into binary fields, although you do need to be able to handle both IP 4-byte v4 and 16-byte v6 addresses.

In my version of the IHttpModule that processes the boomerang beacons, I decided to generate an ETW event from the NavTiming API measurements with an event payload that contains the web client Page Load time measurements. This approach allows me to integrate RUM measurements from the web beacons with other web server-side measurements that can be calculated from other ETW events. In the next section, I will discuss what web server-side measurements can be gathered using ETW, and how I integrated boomerang beacon RUM measurements into IIS web server performance management reporting using those trace events..

Tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *