通过 HTTPS 下载文件 (C#)

发布于 2024-10-20 02:03:29 字数 981 浏览 1 评论 0原文

我有一个表格,用户可以在其中附加 Word 文档和保存在 SQL DB 上。检索这些文档可以通过 http 完美运行,但在 https 上会中断。我正在将文档存储在会话中。这是我检索文件的代码:

Attachments attach = AttachmentsSession[e.Item.ItemIndex] as Attachments;

string extension = attach.Extension;

byte[] bytFile = attach.AttachmentData;

Response.Clear();

Response.Buffer = true;

if (extension == ".doc")

{

    Response.ContentType = "application/vnd.ms-word";

    Response.AddHeader("content-disposition", "attachment;filename=" + attach.Name);

}

else if (extension == ".docx")

{

    Response.ContentType = "application/vnd.openxmlformats-
officedocument.wordprocessingml.document";

    Response.AddHeader("content-disposition", "attachment;filename=" + attach.Name);

}

Response.Charset = "";

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.BinaryWrite(bytFile);

HttpContext.Current.ApplicationInstance.CompleteRequest();

Response.End();

同样,它适用于 http,但不适用于 https 和 https。该文档存储在 SQL DB 中。请帮忙

I have form where user can attach word documents & is saved on SQL DB. Retrieving those documents works flawlessly over http but breaks on https. I'm storing the document in session. Here is my code to retrieve the file:

Attachments attach = AttachmentsSession[e.Item.ItemIndex] as Attachments;

string extension = attach.Extension;

byte[] bytFile = attach.AttachmentData;

Response.Clear();

Response.Buffer = true;

if (extension == ".doc")

{

    Response.ContentType = "application/vnd.ms-word";

    Response.AddHeader("content-disposition", "attachment;filename=" + attach.Name);

}

else if (extension == ".docx")

{

    Response.ContentType = "application/vnd.openxmlformats-
officedocument.wordprocessingml.document";

    Response.AddHeader("content-disposition", "attachment;filename=" + attach.Name);

}

Response.Charset = "";

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.BinaryWrite(bytFile);

HttpContext.Current.ApplicationInstance.CompleteRequest();

Response.End();

Again, it works on http but not on https & the document is stored in SQL DB. Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合约呢 2024-10-27 02:03:29

当您尝试通过 HTTPS 下载时是否收到错误消息?该错误是否仅在使用 IE 时出现?如果是这样,请尝试更改“不保存加密页面”功能
IE高级设置。请参阅以下链接中的信息: http://www.ureader.com/msg/153060.aspx

Are you receiving an error message when you try to download over HTTPS? Does the error only occur while using IE? If so, try changing the "Do not save Encrypted pages" feature in the
IE advanced settings. See the information at the following link: http://www.ureader.com/msg/153060.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文