Redirect a page using a Header

Any keen surfer will be familiar with Affiliate Marketing, its a huge industry with Google's Adwords driving "Pay Per Click" campaigns. Google provide the Adwords application and Google Analytics to track the effectiveness of marketing campaigns from click through, to page view, lead generation and sale, with the tracking easily implemented by inserting a small snippet of JavaScript in the page.

So where does the Redirect fit in?

Affiliate sites merely send clicks through to merchants via an affiliate network, that tracks the referral and the conversion. But to capture the information required for Google's Analytics you need to stick a page in between the viewed page and the referral to execute the Google Analytics snippet.

This is relatively simple and can be achieved a number of ways, but the best method I have discovered is to use the code below. In the Page_Load you simply append a Header to Refresh the page, set the time in seconds before the Refresh occurs and supply the URL.

Response.AppendHeader("Refresh""0; URL=" + Affiliate.TrackingURL);

You won't find this in the source of the page as it's passed in the HTTP response headers to the browser.

Other implementations of this solution?

If you have a web application that requires a user to login, you can use this in conjunction with Session.Timeout to logout a user after a period of in activity between pages in the application.

I hope you find uses for this in your next ASP.Net application.

Author Paul Marshall

A self confessed Microsoft bigot, Paul loves all Microsoft products with a particular fondness for SQL Server. Paul is currently focusing on Web 2.0 patterns and practices and is always looking for better ways of doing things.

I love the .net platform, and I find it to be the most productive toolset I have used to date.

Add Comment


Your comment has been received and will be shown once it passes moderation.