Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET XML VB.NET
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.ClearContent()
    Response.ClearHeaders()
    Response.ContentType = "text/xml"
    Response.Write(Doc.OuterXml)
    Response.End()
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?
 
ADDED
 
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" ?>
<EBulletinData>
  <Item>
    <EBulletinDate>6/9/2010 12:00:00 AM</EBulletinDate>
    <DepartmentId>5</DepartmentId>
    <Id>102</Id>
    <Introduction>
      <![CDATA[<p>Some text here.</p>]]>
    </Introduction>
    <Title>
      <![CDATA[Client Quarterly Available]]>
    </Title>
  </Item>
</EBulletinData>
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.
 
Solution
 
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. D'Oh! | :doh:
 
Never mind, nothing to see here.
Posted 28-Dec-10 9:42am
Edited 28-Dec-10 10:09am
v3
Comments
aspdotnetdev at 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
good
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.ClearContent()
	Response.ClearHeaders()
	Response.ContentType = "text/xml"
	Response.Write("<test>Hello</test>")
	Response.End()
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.
  Permalink  
Comments
Gregory.Gadow at 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 at 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 at 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
0 Sergey Alexandrovich Kryukov 363
1 OriginalGriff 344
2 George Jonsson 238
3 Shemeemsha RA 148
4 Animesh Datta 130
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 28 Dec 2010
Copyright © CodeProject, 1999-2014
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