HttpResponse传输文件 - 停止代码

时间:2016-02-24 20:41:21

标签: c# asp.net httpresponse

我有一个调用此方法的asp.net按钮。

 protected void DownloadFile(object sender, EventArgs e)
        {

            Response.Clear();
            string filePath = getFilePath();
            Response.ContentType = "application/vnd.ms-excel";
            Response.AppendHeader("Content-Disposition", "attachment; filename=FvGReport.xlsx");
            Response.TransmitFile(filePath);
            Response.End();
            newReportMessage.Visible = false;
        }

但是newReportMessage.Visible组件永远不能运行。通过阅读我可以看到Response.End()只是终止线程,所以这是有道理的。所以我尝试过对很多其他人有用的东西。

protected void DownloadFile(object sender, EventArgs e)
        {

            Response.Clear();
            string filePath = getFilePath();
            Response.ContentType = "application/vnd.ms-excel";
            Response.AppendHeader("Content-Disposition", "attachment; filename=FvGReport.xlsx");
            Response.TransmitFile(filePath);
            Response.Flush();
            Response.SuppressContent = true;
            HttpContext.Current.ApplicationInstance.CompleteRequest();

            newReportMessage.Visible = false;
        }

但它仍然不起作用?有谁知道问题是什么,所以我将来可以避免这种情况,解决方案是什么?

0 个答案:

没有答案