File download over HTTPS (C#)
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.SetCacheabil开发者_运维知识库ity(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
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
精彩评论