如何在response.end()中解决threadabortexception。 [英] How to solve threadabortexception in response.end().
本文介绍了如何在response.end()中解决threadabortexception。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hii,
我在下载文本文件时遇到问题。
这是我的码。我在webservice&中写了这段代码。在方法中调用此方法。
但它在Response.end()中显示线程中止错误。
Hii,
I have facing problem while download a text file.
Here is my code. I wrote this code in webservice & call this method inside a method.
But It shows thread aborted Error in Response.end().
public void ErrorLog()
{
try
{
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.ContentType = "application/octet-stream";
response.AppendHeader("Content-Disposition", "attachment; filename=ErrorFile.txt");
string path = System.Web.HttpContext.Current.Server.MapPath("~/ErrorFile.txt");
response.TransmitFile(System.Web.HttpContext.Current.Server.MapPath("~/ErrorFile.txt"));
response.Flush();
response.End();
}
catch (ThreadAbortException ex)
{
Console.Write(ex.ToString());
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
finally
{
//HttpContext.Current.Response.End();
}
}
谢谢
Bigyan Sahoo
我尝试过:
我在这里试试catch块找到错误,但无法解决它们。
Thanks
Bigyan Sahoo
What I have tried:
Here I use try catch block to find error, but unable to solve them.
推荐答案
使用ApplicationInstance.CompleteRequest而不是End。
正确使用System.Web .HttpResponse.Redirect– Thomas Marquardt'博客 [ ^ ]
也把它放在catch块之外。
Use ApplicationInstance.CompleteRequest instead of End.
Correct use of System.Web.HttpResponse.Redirect – Thomas Marquardt's Blog[^]
Also put it outside the catch block.
这篇关于如何在response.end()中解决threadabortexception。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文