2011-03-08 2 views
0

SQL DB에 저장된 파일을 다운로드하려고하면 Firefox에만 문제가 발생합니다 (IE & Chrome에서 문제가 없습니다). 문제는 파일의 확장명을 인식 할 수 없으므로 사용자가 파일을 컴퓨터에 저장하려고 할 때만 나타납니다. 그것은 사용자가 그것을 열려고 시도하고 브라우저가 자사의 단어, 엑셀, 또는 PDF 파일을 감지 할 수 있다면 잘 작동합니다.C# 파일을 다운로드 할 때 https가 넘는 Firefox 문제가 발생합니다.

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(); 

답변

2

내가 그렇게, ProNeticas '소식에 댓글을 달 수 없습니다 :

"응용 프로그램/단어"가 아닌 여기 내 코드 블록이다 공인 된 MIME 형식, .docx에 대한 모든 것 중 가장 적은 것, 그리고 브라우저가 그걸로 무엇을해야하는지 알고 있을지 의심 스럽습니다.

.DOCX에 대한 올바른 MIME 형식은 application/vnd.openxmlformats-officedocument.wordprocessingml.document, 그는 이미 가지고있는 마임 타입 우리는 파이어 폭스이 정확한 문제를 가지고 파일을 XLSX Office Mime Types

+1

1 참조 .DOC

에 대한 올바른 것입니다. 올바른 마임 유형을 보내야하는 것으로 바뀌 었습니다 – NotMe

+0

+1 실제로 허용 된 MIME 유형을 확인하십시오 : http://www.w3schools.com/media/media_mimeref.asp – Justin

0

이 시도 ...

Response.AddHeader('Content-type', 'application/msword'); 
Response.AddHeader('Content-Disposition', 'attachment; filename="file.docx"'); 
관련 문제