gpt4 book ai didi

asp.net - Response.End() 抛出错误

转载 作者:行者123 更新时间:2023-12-01 13:55:59 25 4
gpt4 key购买 nike

在我的应用程序中我需要下载一个文件,所以我使用了这段代码:

 Response.ContentType = "application/octet-stream";                    
Response.AppendHeader("Content-Disposition", "attachment; filename =" + strFileName + ".xls");
Response.TransmitFile(strFilePath);
Response.End();

Response.End() 我收到一个错误 ThreadAbortException

为了避免这个错误,我尝试使用 httpApplication.CompleteRequest(),但我也无法使用它。

httpApplication.CompleteRequest() 的代码如下,

Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename =" + strFileName + ".xls");
Response.TransmitFile(strFilePath);
HttpApplication.CompleteRequest();

我在使用 HttpApplication.CompleteRequest() 时收到此错误

An object reference is required for the non-static field, method, or property 'System.Web.HttpApplication.CompleteRequest()'

我希望我能澄清我的疑问...帮帮我....

最佳答案

Response.End() 预计会抛出一个 ThreadAbortException
这是设计使然,因此不会处理页面响应的其余部分。

得到这个异常是完全可以的,它会确保页面不会被进一步处理。

引用:HttpResponse.End

The CompleteRequest method does not raise an exception, and code after the call to the CompleteRequest method might be executed. If your intention is to avoid execution of subsequent code, and if the performance penalty of End is acceptable, you can call End instead of CompleteRequest.

关于asp.net - Response.End() 抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17270192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com