Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Model view controller 获得;发送HTTP标头后,服务器无法追加标头。”;下载文件出错_Model View Controller - Fatal编程技术网

Model view controller 获得;发送HTTP标头后,服务器无法追加标头。”;下载文件出错

Model view controller 获得;发送HTTP标头后,服务器无法追加标头。”;下载文件出错,model-view-controller,Model View Controller,我在登录页面下载文件后得到 在JS中 $('#DownloadForm').on('click', function (event) { window.location = '/Form/Form1' }); 在控制器中 public void Form1() { string path = Server.MapPath("~/Form/Form.xls") FileStream objFileStream = System.IO.File.OpenRead(

我在登录页面下载文件后得到

在JS中

$('#DownloadForm').on('click', function (event) {       
  window.location = '/Form/Form1'
});
在控制器中

public void Form1()
{
    string path = Server.MapPath("~/Form/Form.xls")
    FileStream objFileStream = System.IO.File.OpenRead(path);
    Response.ContentType = "application/octet-stream";
    Response.AppendHeader("content-disposition", "attachment; filename=" + "Form.xls");
    Response.AppendHeader("content-length", objFileStream.Length.ToString());
    int nSize = 0;
    byte[] arrBuffer = new byte[1024 * 215];
    while ((nSize = objFileStream.Read(arrBuffer, 0, arrBuffer.Length)) > 0)
    {
        Response.OutputStream.Write(arrBuffer, 0, nSize);
        Response.Flush();
    }
    Response.End();
}
我在Global.asax中出错

受保护的无效应用程序\u错误(对象发送方,事件参数e) “发送HTTP标头后,服务器无法追加标头。”


谢谢。

我想你需要从回应开始。清除()

我认为您需要从Response.Clear()开始

嗨,谢谢你的回复。我测试了一下,仍然有错误。如果我从其他页面调用该函数,我没有得到错误,如果我从登录页面调用,我得到错误。嗨,谢谢你的回复。我测试了,仍然得到错误。若我从其他页面调用该函数,我并没有得到错误,若我从登录页面调用,我得到错误。