Export功能 导致 页面显示很多非法字符,还可能页面显示两次

时间:2023-03-08 22:35:27
        private void exportBinaryToExcel(byte[] bytes, string filename)
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.AddHeader("Content-Length", bytes.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytes);
Response.Flush();
Response.End(); //这里的问题
}

发现页面局部展示了两次,思考后感觉是页面展现的方法中没有清空上一次的内容,找到代码Response, Google发现Response.End()是结束当前的页面。解决!