Click here to Skip to main content
12,815,986 members (37,474 online)
Rate this:
Please Sign up or sign in to vote.
I have a page that is invoked as Test.aspx?id=102 that does this:

Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs)
    Dim ThisId As String = Request.QueryString("id")

    Dim Doc As XmlDocument = GenerateData(ThisId)

    Response.Buffer = True
    Response.ContentType = "text/xml"
End Sub

The method GenerateData returns an XmlDocument object containing data retrieved using the query string parameter id.

My problem is that if the URL has a query string, the returned document is treated by the browser as ill-formatted HTML. If I omit the query string and pass a hard coded constant into GenerateData, the returned document is treated like an XML document and displays exactly as I would expect.

I have tried Request.QueryString.Clear and Request.QueryString.Remove("id"), and both generate a "Collection is read-only" error.

I would like to retain the flexibility of passing the search criteria through the query string and not have to deal with the Session object or form submissions. Any suggestions on how to get this to work?


For what it is worth, this is the XML that gets generated whether I use the query string or an inline constant:
<?xml version="1.0" ?>
    <EBulletinDate>6/9/2010 12:00:00 AM</EBulletinDate>
      <![CDATA[<p>Some text here.</p>]]>
      <![CDATA[Client Quarterly Available]]>

With the constant, this is displayed by the browser (IE 8, at least) as a well-formatted XML file. With the query string, this same file is displayed as if it were badly-formatted HTML.


Boy, do I feel like a right idiot. I added the OutputCache Location="None" directive to the page, and suddenly the problem went away. Apparently, the query string version had been cached with some non-obvious errors, and it was this version that the server was returning. :doh:

Never mind, nothing to see here.
Posted 28-Dec-10 10:42am
Updated 28-Dec-10 11:09am
aspdotnetdev 28-Dec-10 16:35pm
I gave you a 5 for having a clear question in the first place and then coming back to explain the problem/solution after you figured it out.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I do not think this has to do with the query string. Perhaps the XML you return when you have a query string is different, and that is why you are seeing a difference? I tried this example:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
	Response.Buffer = True
	Response.ContentType = "text/xml"
End Sub

I tried it in IE8 and Firefox with and without a query string and it always looked like XML.

FYI, the reason you cannot clear the request query string is because you cannot modify the request once it has reached the server. At that point, the request has been made... it is the response you must concern yourself with. If you wanted, you could redirect the response to a different URL, but that doesn't sound like what you want here.
Gregory.Gadow 28-Dec-10 15:58pm
Nope. With or without the query string, I am passing the exact same same value into GenerateData, and the exact same document is being passed back out. The ONLY difference between using and not using the query string is the existence of the query string itself.
aspdotnetdev 28-Dec-10 16:03pm
Hmmm, well my example works fine for me. Can try mine and see if it works for you?
Gregory.Gadow 28-Dec-10 16:10pm
Problem solved with the ingestion of extra caffeine and the use of an OutputCache directive. Thanks anyway.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 28 Dec 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100