IIS7 上
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Connection", "Keep-Alive");
HttpContext.Current.Response.AddHeader("Content-Length ", bytes.Length.ToString());
//通知浏览器下载文件而不是打开
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
HttpContext.Current.Response.BufferOutput = true;
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.Flush(); /*******此处报错******/
HttpContext.Current.Response.Close();
HttpContext.Current.Response.End();
替换掉你原先的那个Flush()