Export (0) Print
Expand All

AdRotator Class

Displays an advertisement banner on a Web page.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public class AdRotator : DataBoundControl
public class AdRotator extends DataBoundControl
public class AdRotator extends DataBoundControl

Use the AdRotator control to display a randomly selected advertisement banner on the Web page. The displayed advertisement changes whenever the page refreshes.

Advertisement information is stored in a separate XML file. The XML file allows you to maintain a list of advertisements and their associated attributes. Attributes include the path to an image to display, the URL to link to when the control is clicked, the alternate text to display when the image is not available, a keyword, and the frequency of the advertisement. Information in this file is not validated by the AdRotator control. To prevent ads from executing malicious scripts, you should always check the data before releasing it, or accept ad information only from trusted sources.

To secure your advertisement file from unauthorized Internet access, do one or more of the following:

  • Store it in the App_Data directory, which is configured to deny Internet access for files of any type.

  • Rename the file with an extension that is not .xml, and map the extension to the HttpForbiddenHandler in Web.config. For more information, see the httpHandlers Element (ASP.NET Settings Schema) section in your Machine.config file.

As an alternative to an XML file as the source of data, it is possible to provide advertisement information through a callback event. This event can also be used in combination with the XML file to extend the behavior of the AdRotator control, such as redirecting to another page. See the AdvertisementFile property for additional information on the file format.

An Impressions attribute can be assigned to each advertisement. It controls how often an advertisement is selected relative to the other advertisements in the advertisement file.

NoteNote

When page caching is enabled, an AdRotator control is not cached. A new advertisement is selected whenever the Web page refreshes. A new advertisement is not selected, however, if you provide an event handler for the AdCreated event.

The following code example demonstrates how to use the AdRotator control to display an advertisement banner on a Web page.

<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
 
 <head>
 </head>
 
 <body>
    <form runat="server">
 
       <h3>AdRotator Example</h3>
 
       <asp:AdRotator id="AdRotator1" runat="server"
            Target="_self"
            AdvertisementFile="~/App_Data/Ads.xml"/>
 
    </form>
 </body>
 
 </html>

The following code example demonstrates the file format for an XML file that contains advertisement information for the previous example. For more information on the file format, see the AdvertisementFile member.

<Advertisements>
  <Ad>
    <ImageUrl>~/Images/image1.jpg</ImageUrl>
    <height>60</height>
    <width>190</width>
    <NavigateUrl>http://www.microsoft.com</NavigateUrl>
    <AlternateText>Microsoft Main Site</AlternateText>
    <Impressions>80</Impressions>
    <Keyword>Topic1</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>~/Images/image2.jpg</ImageUrl>
    <height>90</height>
    <width>90</width>
    <NavigateUrl>http://www.wingtiptoys.com</NavigateUrl>
    <AlternateText>Wingtip Toys</AlternateText>
    <Impressions>80</Impressions>
    <Keyword>Topic2</Keyword>
  </Ad>
</Advertisements>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft