1

I need to render a xml document in either an new asp.net page or a pop up page.

I am following the article

I am getting the following error "Thread was being aborted." but the xml document is rendered in the page.

is there any better example

Try
            If Not String.IsNullOrEmpty(tempFilePath) Then
                Response.Clear()
                Response.Buffer = True
                Response.Charset = ""
                Response.Cache.SetCacheability(HttpCacheability.NoCache)
                Response.ContentType = "application/xml"
                'Response.WriteFile(Server.MapPath(tempFilePath)) ' Todo Change path to temp location and add th
                Response.WriteFile("c:\Test.xml")
                Response.Flush()
                Response.[End]()
            End If
        Catch ex As Exception
            'TODO 
            Throw ex

        End Try
user1339913
  • 1,017
  • 3
  • 15
  • 36
  • 1
    Please specify line where you are getting that exception (note that `Response.End` explicitly throws that exception as result of aborting the current thread- http://stackoverflow.com/questions/1087777/is-response-end-considered-harmful) – Alexei Levenkov Sep 25 '15 at 15:16
  • Thank you that worked I replaced response.end with response.close . Can you add that as an answer . If I need to render the response in a page that has the master page how would I do that. – user1339913 Sep 25 '15 at 15:32

1 Answers1

0

Response.End explicitly throws that exception as result of aborting the current thread (Is Response.End() considered harmful?) - so if you are logging all exceptions or just watching in debugger you'll see ThreadAbortException.

To stop sending extra content you can follow recommendation in linked question (C#):

  Response.Flush();
  Response.SuppressContent = True
  HttpContext.Current.ApplicationInstance.CompleteRequest()

Based on your comment you are trying to render XML as part of the same response as main HTML of the page and it is not really possible (at least end result will not be "downloadable file"). It is generally easier to serve files from separate handler that does not have any HTML rendering associated.

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179