This article demonstrates how to use the ASP.NET AdRotator control to display advertisements in an ASP.NET Web site. The attached source code also implements custom "click tracking" logic.
1. Introduction
Many e-commerce websites use banner advertisements to promote products and services on behalf of their customers. Websites also need to not only display ads but also need to rotate.
ASP.NET AdRotator control allows developers to place image ads on a Web Form and provides programmatic functionality that enables the development of custom logic to track advertisement clicks. The AdRotator control randomly selects banner ads from a list that is specified in an external XML. The XML also has a click URL.
2. ASP.NET Website Project
First of all, start Visual Studio and create a new ASP.NET Web Site. I'm using Visual Studio 2008. If you're using a newer version of Visual Studio, just create an ASP.NET Website using a Web Form or MVC.

Figure 1.
3. Create the Ad XML file
Add a new XML File using Add New Item in Visual Studio. Right click on Visual Studio project name in Solution Explorer, Add New Item, and select XML file.
Figure 2.
Add the following code or similar code in the XML. The root node of the XML file is Advertisement and it has multiple Ad tags. Each Ad tag has an ImageURL, NavigateUrl, AlternateText, Impressions, Keyword, and Category.
Note: You need to replace these values with your own values.
- <?xml version="1.0" encoding="utf-8" ?>
- <Advertisements>
- <Ad>
- <ImageUrl>~/Banners/468X60_add.gif</ImageUrl>
<NavigateUrl>http://www.Mindcracker.com/Registration/Register.aspx</NavigateUrl> - <AlternateText>Advertisement</AlternateText>
- <Impressions>100</Impressions>
- <Keyword>Header</Keyword>
- <Category>Script</Category>
- </Ad>
- <Ad>
- <ImageUrl>~/Banners/468X60_Consultant.gif</ImageUrl>
- <NavigateUrl>http://www.mindcracker.com/Consultants/</NavigateUrl>
- <AlternateText>Advertisement</AlternateText>
- <Impressions>100</Impressions>
- <Keyword>Header</Keyword>
- <Category>Script</Category>
- </Ad>
- <Ad>
- <ImageUrl>~/Banners/468X60_Employer.gif</ImageUrl>
- <NavigateUrl>http://www.Mindcracker.com/Registration/Register.aspx</NavigateUrl>
- <AlternateText>Advertisement</AlternateText>
- <Impressions>100</Impressions>
- <Keyword>Header</Keyword>
- <Category>Script</Category>
- </Ad>
- <Ad>
- <ImageUrl>~/Banners/468X60_Jobseeker.gif</ImageUrl>
- <NavigateUrl>http://www.mindcracker.com/Jobs/</NavigateUrl>
- <AlternateText>Advertisement</AlternateText>
- <Impressions>100</Impressions>
- <Keyword>Header</Keyword>
- <Category>Script</Category>
- </Ad>
- <Ad>
- <ImageUrl>~/Banners/468X60_Recruiter.gif</ImageUrl>
<NavigateUrl>http://www.Mindcracker.com/Registration/Register.aspx</NavigateUrl> - <AlternateText>Advertisement</AlternateText>
- <Impressions>100</Impressions>
- <Keyword>Header</Keyword>
- <Category>Script</Category>
- </Ad>
- </Advertisements>



Pankajkumar PatelPosted Aug 20, 2019, 12:12 AM
Nice article
arjun prasadPosted Mar 11, 2013, 1:41 AM
good
prisilla jayarajPosted Feb 1, 2011, 9:57 AM
in adrotator why image of the advertisement was not displayed?wat is the reason?
martinPosted Jan 23, 2010, 6:43 AM
Hi, works, shows alternate text, links... but does not display pictures. Any ideas? Thank you in advance. Martin