AdRotator Class

Displays an advertisement banner on a Web page.

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

public ref class AdRotator : public 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.


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.

No code example is currently available or this language may not be supported.

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.

    <AlternateText>Microsoft Main Site</AlternateText>
    <AlternateText>Wingtip Toys</AlternateText>

  • AspNetHostingPermission  for operating in a hosted environment. Demand value: LinkDemand. Permission value: Minimal.
  • AspNetHostingPermission  for operating in a hosted environment. Demand value: InheritanceDemand. Permission value: Minimal.

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