Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: Ad Rotator Error Occurs When AdUrls Contain an Ampersand (&) Symbol


View products that this article applies to.

This article was previously published under Q321812

↑ Back to the top


Symptoms

If the AdUrl in an XML file that is associated with an AdRotator WebForms control contains an ampersand (&) symbol, you receive the following server error message:
Server Error in '/AppName' Application.

This is an unexpected token. Expected 'SEMICOLON'. Line 8, position 53

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: This is an unexpected token. Expected 'SEMICOLON'. Line 8, position 53.

↑ Back to the top


Cause

The error message occurs because the & symbol invalidates the XML file that is associated with the AdRotator control.

↑ Back to the top


Resolution

If you have to put an & symbol in the XML file (such as in the querystring of the URL specified for the NavigateUrl), you must replace it with & (the ampersand symbol, "amp", and a semicolon).

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More information

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET and create a new Web application project in either Microsoft Visual C# .NET or in Microsoft Visual Basic .NET.
  2. In the Design view, drag an AdRotator server control to the default WebForm1.aspx page.
  3. Modify the properties of the AdRotator control so as to set the AdvertisementFile attribute to an XML file. The following code is a sample XML file that will cause the error to occur:
    <?xml version="1.0" encoding="utf-8" ?>
    <Advertisements>
        <Ad>
            <NavigateUrl>http://localhost/test.aspx?a=2</NavigateUrl>
            <AlternateText>ad1</AlternateText>
        </Ad>
        <Ad>
            <NavigateUrl>http://localhost/test.aspx?a=1&b=1</NavigateUrl>
            <AlternateText>ad2</AlternateText>
        </Ad>
    </Advertisements>
    					
  4. Save all the files, and then build the project.
  5. View the WebForm1.aspx page in the browser. You can expect to see the error mentioned in "Symptoms".
NOTE: The Webform appears correctly if (in the code in step 3) you just replace the & symbol with &amp;.

↑ Back to the top


References

For more information about AdRotator server controls and ASP.NET server controls, visit the following MSDN and Microsoft Knowledge Base Web sites:
306459� INFO: ASP.NET Server Controls Overview

↑ Back to the top


Keywords: KB321812, kbwebforms, kbservercontrols, kbprb

↑ Back to the top

Article Info
Article ID : 321812
Revision : 6
Created on : 7/8/2003
Published on : 7/8/2003
Exists online : False
Views : 517