ASP.NET - AD-Rotater

An Ad Rotator is a control in ASP.NET that allows you to display a sequence of advertisements on a web page. The Ad Rotator control can be used to display text, images, or Flash advertisements in a rotating sequence.

The Ad Rotator control is useful when you have multiple advertisements that you want to display on your web page, but you don't want to display them all at once. Instead, you can use the Ad Rotator control to display them one at a time in a rotating sequence, which helps to keep the content on your web page fresh and interesting.

To use the Ad Rotator control, you need to create a file that contains the details of your advertisements, including the image or text, the URL to link to, and the display frequency. You can then configure the Ad Rotator control to use this file and display the advertisements in a rotating sequence.

Example 1: Displaying Text Ads

In this example, we'll create an XML file that contains the details of our text ads, and then use the AdRotator control to display them on our web page.

Create a new XML file in your project, and name it TextAds.xml. The contents of the file should look like this:

<Advertisements>
  <Ad>
    <ImageUrl></ImageUrl>
    <NavigateUrl>http://www.example.com/</NavigateUrl>
    <AlternateText>Example Ad 1</AlternateText>
  </Ad>
  <Ad>
    <ImageUrl></ImageUrl>
    <NavigateUrl>http://www.example.com/</NavigateUrl>
    <AlternateText>Example Ad 2</AlternateText>
  </Ad>
  <Ad>
    <ImageUrl></ImageUrl>
    <NavigateUrl>http://www.example.com/</NavigateUrl>
    <AlternateText>Example Ad 3</AlternateText>
  </Ad>
</Advertisements>

Add the following code to your web form:

<asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="TextAds.xml" AdProperties="AlternateText,NavigateUrl" />

This code will display the text ads in the TextAds.xml file, and will use the AlternateText and NavigateUrl properties to display the ad text and link.

Example 2: Displaying Image Ads

In this example, we'll create an XML file that contains the details of our image ads, and then use the AdRotator control to display them on our web page.

Create a new XML file in your project, and name it ImageAds.xml. The contents of the file should look like this:

<Advertisements>
  <Ad>
    <ImageUrl>~/Images/ad1.jpg</ImageUrl>
    <NavigateUrl>http://www.example.com/</NavigateUrl>
    <AlternateText>Example Ad 1</AlternateText>
  </Ad>
  <Ad>
    <ImageUrl>~/Images/ad2.jpg</ImageUrl>
    <NavigateUrl>http://www.example.com/</NavigateUrl>
    <AlternateText>Example Ad 2</AlternateText>
  </Ad>
  <Ad>
    <ImageUrl>~/Images/ad3.jpg</ImageUrl>
    <NavigateUrl>http://www.example.com/</NavigateUrl>
    <AlternateText>Example Ad 3</AlternateText>
  </Ad>
</Advertisements>

Add the following code to your web form:

This code will display the image ads in the ImageAds.xml file, and will use the ImageUrl, NavigateUrl, and AlternateText properties to display the ad image, link, and alt text.