Microsoft KB Archive/321812

From BetaArchive Wiki

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

STATUS

This behavior is by design.

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 &.

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



Additional query words: AdRotator

Keywords: kbwebforms kbprb kbservercontrols KB321812