Sideway from Sideway


Draft for Information Only


Links of AdRotator Class from
 AdRotator Class
 XML Advertisement File Format
 Explicit Interface Implementations
 Extension Methods
 Applies to
 See also

Links of AdRotator Class from


AdRotator Class

Namespace: System.Web.UI.WebControls

Assembly: System.Web.dll

Displays an advertisement banner on a Web page.

public class AdRotator : System.Web.UI.WebControls.DataBoundControl

Inheritance Object --> Control --> WebControl --> AdRotator


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 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.

Note: 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.

XML Advertisement File Format

The AdRotator control uses a separate XML advertisement file to store the advertisement information, such as the location of the image to display and the URL of the page to link to. The AdvertisementFile property of the AdRotator control specifies the path to this file.

When creating the advertisement file, opening and closing <Advertisements> tags mark the beginning and the end of the file, respectively. Opening and closing <Ad> tags delimit each advertisement. All advertisements are nested between the opening and closing <Advertisements> tags. If the file contains multiple <Advertisements> tags, only the first set of <Advertisements> tags in the file will be parsed by the AdRotator control. All other <Advertisements> tags will be ignored.

The data elements for each advertisement are nested between the opening and closing <Ad> tags. Although certain data elements are predefined (such as ImageUrl and NavigateUrl), you can place custom elements between the <Ad> tags. These elements will be read by the AdRotator control when it parses the file. The information is then passed to the AdCreated event in the AdProperties dictionary property.

The following table lists the data elements that are predefined for the XML advertisement file.

  • ImageUrl: The absolute or relative URL to an image file (optional).
  • NavigateUrl: The URL of a page to link to if the user clicks the ad (optional). Note: If this element is not set, the HRef property is not rendered on the anchor tag.
  • Height: The height of the image, in pixels (optional).
  • Width: The width of the image, in pixels (optional).
  • AlternateText: The text display in place of the image when the image specified by the ImageUrl property is not available (optional). In some browsers, this text also appears as a ToolTip for the advertisement.
  • Keyword: A category for the advertisement (for example, "computers") that you can filter by (optional).
  • Impressions: A number that indicates the importance of the ad in the schedule of rotation relative to the other ads in the file (optional). The larger the number, the more often the ad is displayed. The total of all <Impressions> values in the XML file cannot exceed 2,047,999,999. If it does, the AdRotator control throws a run-time exception.





Explicit Interface Implementations

Extension Methods

Applies to

.NET Framework: 4.8 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6 4.5.2 4.5.1 4.5 4.0 3.5 3.0 2.0 1.1

See also



  1. Active Server Pages,, updated 20Dec2012
  2. ASP Overview,, updated 21Dec2012
  3. ASP Best Practices,, updated 15Apr2013
  4. ASP Built-in Objects,, updated 20Dec2012
  5. Response Object,, updated 20Dec2012
  6. Request Object,, updated 20Dec2012
  7. Server Object (IIS),, updated 20Dec2012
  8. Application Object (IIS),, updated 20Dec2012
  9. Session Object (IIS),, updated 20Dec2012
  10. ASPError Object,, updated 20Dec2012
  11. ObjectContext Object (IIS),, updated 20Dec2012
  12. Debugging Global.asa Files,, updated 15Apr2013
  13. How to: Debug Global.asa files,, updated 15Apr2013
  14. Calling COM Components from ASP Pages,, updated 15Apr2013
  15. IIS ASP Scripting Reference,, updated 15Apr2013
  16. ASP Keywords,, updated 15Apr2013
  17. Creating Simple ASP Pages,, updated 15Apr2013
  18. Including Files in ASP Applications,, updated 15Apr2013
  19. ASP Overview,, updated 15Apr2013
  20. FileSystemObject Object,, updated 14Mayr2013
  21., ADO Object Model, updated 15Apr2013
  22. ADO Fundamentals,, updated 14Mayr2013

ID: 190600022 Last Updated: 2019/6/22 Revision: Ref:


Home (5)



HBR (3)



Hobbies (7)


Chinese (1097)

English (336)

Reference (66)


Hardware (149)


Application (187)

Digitization (24)

Numeric (19)


Web (644)new



Regular Expression (SC)


Knowledge Base

Common Color (SC)

Html Entity (Unicode) (SC)

Html 401 Special (SC)

OS (389)new

MS Windows

Windows10 (SC)

.NET Framework (SC)

DeskTop (7)



Formulas (8)

Number Theory (206)

Algebra (20)

Trigonometry (18)

Geometry (18)

Calculus (67)

Complex Analysis (21)


Tables (8)


Mechanics (1)

Rigid Bodies

Statics (92)

Dynamics (37)

Fluid (5)

Fluid Kinematics (5)


Process Control (1)

Acoustics (19)

FiniteElement (2)

Biology (1)

Geography (1)

Latest Updated Links

Copyright © 2000-2019 Sideway . All rights reserved Disclaimers last modified on 10 Feb 2019