2011-03-03 106 views
0

我有一個窗體,用戶可以在其中附加word文檔&保存在SQL數據庫中。檢索這些文件完美地通過HTTP工作,但在https上打破。我在會話中存儲文檔。這裏是我的代碼來檢索文件:通過HTTPS(C#)下載文件

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 &的文檔存儲在SQL數據庫。請幫助

+0

對於混淆感到抱歉。讓我再解釋一遍。用戶無論是http還是https,都可以上傳文件。但是當管理員進入網絡界面時,他們無法下載用戶通過https上傳的文件。上面的代碼是爲管理員下載文件 – 2011-03-03 19:34:06

回答

0

當您嘗試通過HTTPS下載時,您是否收到錯誤消息?錯誤只發生在使用IE瀏覽器?如果是這樣,請嘗試更改 IE高級設置中的「不保存加密頁面」功能。請參閱以下鏈接的信息:http://www.ureader.com/msg/153060.aspx

+0

IE拋出以下錯誤 - >「Internet Explorer無法打開這個Internet站點,請求的站點不可用或找不到,請稍後再試。」即使是由於某種原因,Firefox也不知道文件的擴展名是什麼,也無法自動檢測到它的文件。這只是通過https – 2011-03-03 20:48:23

+0

關注的問題請參閱以下MS KB文章:http://support.microsoft.com/kb/316431如果可以,我會嘗試刪除無緩存頭。如果它明確在頁面中,你可以編輯它。如果您需要爲整個站點或服務器執行此操作,請參閱http://support.microsoft.com/kb/247404 – p1lgr1m 2011-03-09 15:53:30