Export (0) Print
Expand All

AdRotator.AdvertisementFile Property

Gets or sets the path to an XML file that contains advertisement information.

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

[BindableAttribute(true)]
public string AdvertisementFile { get; set; }
<asp:AdRotator AdvertisementFile="String" />

Property Value

Type: System.String
The location of an XML file containing advertisement information. The default value is an empty string ("").

Use the AdvertisementFile property to specify the location of an XML file that contains advertisement information. The XML file must reside within the same Web site. For deployment and security purposes, it is strongly recommended that you place the file in the same Web application. It is only possible to access an XML file that is located in a different application on the same site if the application has sufficient trust.

You can set this property to either an absolute path or a path relative to the XML file. Use a relative path to simplify deployment. If you use a relative path, that path is relative to the location of the page or user control that contains the AdRotator control.

The AdvertisementFile property is optional. An advertisement can also be programmatically set in the AdCreated event.

The XML file contains the following predefined attributes. Only the ImageUrl attribute is required.

Attribute

Description

ImageUrl

The URL of the image to display.

Height

The height of the image, in pixels (optional).

Width

The width of the image, in pixels (optional).

NavigateUrl

The URL of the page to navigate to when the AdRotator control is clicked.

AlternateText

The text to display if the image is unavailable. On some browsers, this text is displayed as a ToolTip.

Keyword

The category for the advertisement. This is used by the AdRotator control to filter the list of advertisements for a specific category.

Impressions

A value that indicates how often an advertisement is displayed in relation to other advertisements in the XML file.

NoteNote

The ImageUrl and NavigateUrl attributes can be a full URL, a root-relative path, or a relative path. If you use a root-relative path, the path is relative to the same Web site. If you use a relative path, the path is relative to the directory that contains the advertisement file.

You can also include custom attributes by using custom tags in the XML file. All attribute tags are parsed from the advertisement file, and the values are placed in the AdProperties dictionary. You can use the AdProperties dictionary to programmatically access your custom attributes.

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 Data directory, which is configured in Machine.config to deny Internet access for files of any type.

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

TopicLocation
Walkthrough: Displaying and Tracking Advertisements with the AdRotator ControlBuilding ASP .NET Web Applications in Visual Studio

The following code example demonstrates how to use the AdvertisementFile property to specify the location of the XML file that contains advertisement information.

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

 <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 shows the file format of the XML advertisement file.

<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>
    <Caption>This is the caption for Ad#1</Caption> 
  </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>
    <Caption>This is the caption for Ad#2</Caption> 
  </Ad>
</Advertisements>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft