Asp net track outbound links

Asp net track outbound links Track outbound links.

Assume you have a website containing links which are out of your domain and you want to track user activity on those links. The simplest solution works with JQuery. You need to attach click event to all hyperlinks and pass that information to server asynchronously without affecting user experience,

One more thing I would like to tell you here is. I’m not using any Ajax call to post the data of what user has clicked. Instead I will show you how you can use Image Tracking http handler technique.

Image tracking Generic handler.

<%@ WebHandler Language="C#" Class="ImageTrackingHandler" %>

using System;
using System.Web;

public class ImageTrackingHandler : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        string url = context.Request.QueryString["track"];
        // You can store this url in data base against users or dates etc. or a
    public bool IsReusable {
        get {
            return false;


As you can see above when java script image element requests image via ImageHttpHandler, the code above process the request.

Script user to call image http handler.

var x = document.createElement("img");  x.src= "ImageTrackingHandler.ashx?track="+url;

Let’s see how to track hyperlink click events.

<script src=""></script>

<script type="text/javascript" language="javascript">


        $("a").click( function() {    

            alert($(this).context.href + " has been clicked ");

            url = $(this).context.href;

            var x = document.createElement("img");
              x.src= "ImageTrackingHandler.ashx?track="+url;



The technique used above can be used to track user activities on page. You can also track image click or anything clicked on your web page.

The reason I’m not posting data via Ajax post is that because I think it would be more bulky.


Asp net track outbound 2.0 step by step Membership Provider Interview Questions for 2 years or 3 years experianceASP net Write Text On Image and delete file file on Server and codeasp net image uploadHigh performance aspnet monitor server Remove internet Convert String To File Handling


My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.

I'm Satalaj.