通过 HTTPS 下载文件 (C#)
我有一个表格,用户可以在其中附加 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您尝试通过 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