Microsoft KB Archive/321812

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

Article ID: 321812

Article Last Modified on 7/8/2003

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft ASP.NET 1.0

-



This article was previously published under Q321812



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.



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



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 &amp; (the ampersand symbol, &quot;amp&quot;, and a semicolon).



STATUS
This behavior is by design.



Steps to Reproduce the Behavior
 Start Microsoft Visual Studio .NET and create a new Web application project in either Microsoft Visual C# .NET or in Microsoft Visual Basic .NET. In the Design view, drag an AdRotator server control to the default WebForm1.aspx page.  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:    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> </li> Save all the files, and then build the project.</li> View the WebForm1.aspx page in the browser. You can expect to see the error mentioned in &quot;Symptoms&quot;.</li></ol>

NOTE: The Webform appears correctly if (in the code in step 3) you just replace the & symbol with &amp;.

<div class="references_section">