【问题标题】:Alternative to Content-Disposition in HTTP Header (c#)HTTP Header 中 Content-Disposition 的替代方案 (c#)
【发布时间】:2009-08-05 15:52:44
【问题描述】:

是否有“附件;文件名=...”的内容处置的替代方法

我正在发送一个流式传输的 exe 文件,并希望浏览器在我开始发送时打开“另存为”或“运行”。

我正在使用 C# HttpResponseHeader 并希望使用它的成员或 HttpWorkerRequest 成员。

谢谢,摩西

【问题讨论】:

  • Content-Disposition 标头有什么问题?
  • 同意。 Content-Disposition 是让浏览器提示用户保存文件的正确方法。使用HttpResponse.AppendHeader()添加header值,即:Response.AppendHeader("Content-Disposition", "attachment; filename=...")
  • 注意:如果您省略 content-type 标头,某些浏览器(例如 Opera)会给文件提供错误的文件扩展名,无论您选择什么。
  • "附件;文件名="没用?然后尝试 Response.AddHeader("content-type", "application/octet-stream")。这将强制显示“另存为/打开方式”对话框。
  • Content-disposition 存在一些安全问题,不是 HTTP 1.1 的一部分

标签: c# http-headers httpresponse content-disposition


【解决方案1】:

Content-Disposition 是让浏览器提示用户保存文件的正确方法。使用HttpResponse.AppendHeader()添加header值,例如:

Response.AppendHeader("Content-Type", "...") 
Response.AppendHeader("Content-Disposition", "attachment; filename=...") 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2011-09-27
    • 2011-12-28
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    相关资源
    最近更新 更多