當我嘗試下載存儲在SQL DB中的文件時,我只對Firefox有一個非常奇怪的問題(適用於IE瀏覽器& Chrome)。僅當用戶嘗試將文件保存在其計算機上時纔會出現問題,因爲它無法識別文件的擴展名。如果用戶試圖打開它並且瀏覽器能夠檢測到它是否爲word,excel或pdf文件,那麼它工作正常。這裏是我的代碼塊:C#文件通過https與Firefox問題下載https
Attachments attach = AttachmentsSession[e.Item.ItemIndex] as Attachments;
string extension = attach.Extension;
byte[] bytFile = attach.AttachmentData;
string fileName = attach.Name;
Response.ClearHeaders();
Response.Clear();
Response.Buffer = true;
if (extension == ".doc")
{
Response.ContentType = "application/vnd.ms-word";
Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
}
else if (extension == ".docx")
{
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
}
Response.Charset = "";
Response.BinaryWrite(bytFile);
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.End();
+1我們不得不用Firefox這個確切問題,XLSX文件。它歸結爲必須發送正確的MIME類型 – NotMe 2011-03-08 18:59:42
+1,看看在這裏接受的MIME類型: http://www.w3schools.com/media/media_mimeref.asp – Justin 2011-03-08 19:01:43