AdRotator 类

在网页上显示公布标题。

**命名空间:**System.Web.UI.WebControls
**程序集:**System.Web(在 system.web.dll 中)

语法

声明
Public Class AdRotator
    Inherits DataBoundControl
用法
Dim instance As AdRotator
public class AdRotator : DataBoundControl
public ref class AdRotator : public DataBoundControl
public class AdRotator extends DataBoundControl
public class AdRotator extends DataBoundControl

备注

使用 AdRotator 控件来在网页上显示随机选定的公布标题。每当该页刷新时,显示的广告都会发生变化。

公布信息存储在单独的 XML 文件中。XML 文件使您可以维护公布及其关联属性的列表。属性包含要显示的图像的路径、单击控件时要链接到的 URL、图像不可用时显示的替换文字、关键字以及发布广告的频率。此文件中的信息不由 AdRotator 控件进行验证。若要防止广告执行恶意脚本,应始终在发布前检查数据,或只接受来自受信任的源的广告信息。

若要保护广告文件以拒绝未经授权的 Internet 访问,请执行下列一项或多项操作:

  • 将其存储在 App_Data 目录中,该目录被配置为拒绝对任何类型的文件进行 Internet 访问。

  • 使用非 .xml 的扩展名对文件进行重命名,并将该扩展名映射到 Web.config 中的“HttpForbiddenHandler”。有关更多信息,请参见您的 Machine.config 文件中的 httpHandlers 元素(ASP.NET 设置架构) 节。

作为 XML 文件的替换数据源,它可以通过回调事件提供广告信息。此事件还可与 XML 文件结合使用以扩展 AdRotator 控件的行为(如重定向到另一页)。有关文件格式的附加信息,请参见 AdvertisementFile 属性。

Impressions 属性可分配给每个公布。它控制相对于公布文件中的其他公布,选择某个公布的频度。

提示

在启用页缓存的情况下,AdRotator 控件不会被缓存。每当网页刷新时就选择新的公布。但是,如果为 AdCreated 事件提供事件处理程序,则不会选择新广告。

主题 位置
演练:使用 AdRotator 控件显示和跟踪广告 在 Visual Studio 中构建 ASP .NET Web 应用程序
如何:使用 AdRotator Web 服务器控件显示 XML 文件中的广告 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:使用 AdRotator Web 服务器控件显示数据库中的广告 在 Visual Studio 中生成 ASP .NET Web 应用程序
演练:使用 AdRotator 控件显示和跟踪广告 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:以编程方式在 AdRotator Web 服务器控件中选择广告 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:使用 AdRotator Web 服务器控件显示 XML 文件中的广告 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:使用 AdRotator Web 服务器控件显示数据库中的广告 在 Visual Studio 中生成 ASP .NET Web 应用程序
演练:使用 AdRotator 控件显示和跟踪广告 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:以编程方式在 AdRotator Web 服务器控件中选择广告 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:使用 AdRotator Web 服务器控件显示 XML 文件中的广告 生成 ASP .NET Web 应用程序
如何:使用 AdRotator Web 服务器控件显示数据库中的广告 生成 ASP .NET Web 应用程序
如何:以编程方式在 AdRotator Web 服务器控件中选择广告 生成 ASP .NET Web 应用程序

示例

下面的代码示例演示如何使用 AdRotator 控件在网页上显示广告横幅。

<%@ Page Language="VB" 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>
<%@ 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>
<%@ Page Language="JScript" 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>

下面的代码示例演示包含前一示例的广告信息的 XML 文件的文件格式。有关文件格式的更多信息,请参见 AdvertisementFile 成员。

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

.NET Framework 安全性

继承层次结构

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

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

AdRotator 成员
System.Web.UI.WebControls 命名空间
AdCreatedEventArgs 类
AdCreatedEventHandler 委托
AdvertisementFile

其他资源

AdRotator Web 服务器控件