Avoid Cookie Stuffing in your affiliate program
By Gal Ratner
If you run or write affiliate programs, you might be aware of "Cookie Stuffing".
Affiliates that are loading your links into small images in their pages in order to send an affiliate code cookie to the client browser and credit themselves with sales that may or may not accrue sometime in the future by a customer that is unaware that an affiliate cookie for Amazon.com has been planted on their computer by a different site.
This is a major revenue loss for many online businesses.
If you are coding an ASP.NET affiliate program, here is a little C# code snippet to help detect Cookie Stuffing
If the page is linked from an iframe or a frame, the script redirects the page to itself with an added parameter. If the parameter is detected, the affiliate cookie is not dropped.
Simple yet effective.
<%@ Application Language="C#" %>
void Application_PreRequestHandlerExecute(object sender, EventArgs e)
string AffiliateCode = Request.QueryString["AffiliateCode"];
if (Session[AffiliateCode] == null)
Session[AffiliateCode] = "Checked";
Session[AffiliateCode] = null;
public void CheckFrame(string AffiliateCode)
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"if (top.location != location)");
sb.Append(@"location.href = location + '&Frame=True';");
public void DropAffiliateCookie(string AffiliateCode)
HttpCookie AffiliateCookie = new HttpCookie("AffiliateCode", AffiliateCode);
AffiliateCookie.Expires = DateTime.Now.AddMonths(1);
You can place the code in your global.asax page and get as creative as you like with the script.