【问题标题】:Download Item With Response下载带有响应的项目
【发布时间】:2013-06-06 23:01:06
【问题描述】:

我想允许客户端下载附件。这里attachment.AttachmentContent 是文件中的字节数组。当我单击按钮下载附件时,它会在下面运行此代码。但我有以下脚本错误。我应该怎么做才能修复它?

未捕获的 Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException:消息 从服务器收到的无法解析。造成这种情况的常见原因 错误是通过调用 Response.Write() 修改响应时, 响应过滤器、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();

【问题讨论】:

    标签: c# asp.net web download


    【解决方案1】:

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

    最常见的原因是您的下载按钮位于 UpdatePanel 内。

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

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

    <Triggers>
        <asp:PostBackTrigger ControlID="Download_Click">
    </Triggers>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      • 2012-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多