下载响应项目

我想允许客户端下载附件。 这里attachment.AttachmentContent是文件中的字节数组。 当我点击按钮下载附件时,它会运行以下代码。 但是我有以下脚本错误。 我该怎么做才能解决这个问题?

未捕获的Sys.WebForms.PageRequestManagerParserErrorException:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息。 此错误的常见原因是通过调用Response.Write(),响应filter,HttpModules或服务器跟踪来修改响应。 详细信息:在’ JFIF“’附近解析时出错。

 Attachment attachment = _attachmentService.GetAttachmentBytesById(int.Parse(e.CommandArgument.ToString())); Response.Clear(); Response.ClearHeaders(); Response.ContentType = "image/jpeg"; Response.AddHeader("Content-Disposition", "attachment; filename=\"" + "test.jpg" + "\""); Response.OutputStream.Write(attachment.AttachmentContent, 0, attachment.AttachmentContent.Length); Response.End(); 

似乎您在部分响应中发送此文件下载。

如果您的下载按钮位于UpdatePanel内,则最常见的原因。

文件只能在完整的PostBack上发送。

您可以将下载按钮设置为PostBack触发器来解决此问题。