AdRotator Class
This page is specific to:.NET Framework Version:1.12.03.03.54.0
.NET Framework Class Library
AdRotator Class

Displays an advertisement banner on a Web page.

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

'Usage

Dim instance As AdRotator

'Declaration

<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class AdRotator _
    Inherits DataBoundControl
<asp:AdRotator />
Remarks

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.

TopicLocation
How to: Display Ads From a Database Using the AdRotator Web Server ControlBuilding ASP .NET Web Applications
How to: Display Ads From a Database Using the AdRotator Web Server ControlBuilding ASP .NET Web Applications
How to: Display Ads From a Database Using the AdRotator Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
How to: Display Ads From a Database Using the AdRotator Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
How to: Display Ads From an XML File Using the AdRotator Web Server ControlBuilding ASP .NET Web Applications
How to: Display Ads From an XML File Using the AdRotator Web Server ControlBuilding ASP .NET Web Applications
How to: Display Ads From an XML File Using the AdRotator Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
How to: Display Ads From an XML File Using the AdRotator Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
How to: Select Ads in an AdRotator Web Server Control ProgrammaticallyBuilding ASP .NET Web Applications
How to: Select Ads in an AdRotator Web Server Control ProgrammaticallyBuilding ASP .NET Web Applications
How to: Select Ads in an AdRotator Web Server Control ProgrammaticallyBuilding ASP .NET Web Applications in Visual Studio
How to: Select Ads in an AdRotator Web Server Control ProgrammaticallyBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Displaying and Tracking Advertisements with the AdRotator ControlBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Displaying and Tracking Advertisements with the AdRotator ControlBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Displaying and Tracking Advertisements with the AdRotator ControlBuilding ASP .NET Web Applications in Visual Studio
Examples

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

<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >

 <head runat="server">
    <title>AdRotator Example</title>
</head>

 <body>
    <form id="form1" 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>
.NET Framework Security

Inheritance Hierarchy

System..::.Object
  System.Web.UI..::.Control
    System.Web.UI.WebControls..::.WebControl
      System.Web.UI.WebControls..::.BaseDataBoundControl
        System.Web.UI.WebControls..::.DataBoundControl
          System.Web.UI.WebControls..::.AdRotator
Thread Safety

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

Other Resources

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View