2015-09-25 78 views
1

我需要在新的asp.net页面或弹出页面中呈现xml文档。在浏览器vb.net中显示Xml文档

我下面的article

我收到以下错误"Thread was being aborted."但XML文档中的页面呈现。

有没有更好的例子

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 
+1

请指定你得到该异常的行(请注意'Response.End'显式抛出异常作为中止当前线程的结果 - http://stackoverflow.com/questions/1087777/is-response-end-认为有害) –

+0

谢谢你的工作,我用response.close替换了response.end。你可以添加一个答案。如果我需要在具有母版页的页面中呈现响应,我将如何执行此操作。 – user1339913

回答

0

Response.End明确地抛出该异常中止作为当前线程(Is Response.End() considered harmful?)的结果 - 所以,如果你正在登录的所有异常,或只是看着调试器中你会看到ThreadAbortException

要停止发送额外的内容,你可以按照推荐的链接的问题(C#):

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

基于您的评论你试图渲染XML作为作为页面的主HTML相同的响应的一部分,这是不可能的(至少最终的结果不会是“可下载的文件”)。从单独的处理程序提供没有任何HTML呈现关联的文件通常更容易。