ASP.NET을 사용하여 .jar 파일을 전송하고 있습니다. 이 코드는 IE에서 완벽하게 작동합니다. 그러나 Firefox에서는 파일이 다운로드되고 손상됩니다. 그것을 고치는 가장 좋은 방법은 무엇입니까? 아래는 내가 사용하고있는 코드입니다.ASP.NET에서 Firefox에서 파일을 전송해야하는 다른 방법이 있습니까?
private void TransferFile()
{
try
{
string filePath = Server.MapPath("SomeJarFIle.jar");
FileInfo file = new FileInfo(filePath);
if (file.Exists)
{
// Clear the content of the response
//Response.ClearContent();
Response.Clear();
// LINE1: Add the file name and attachment, which will force the open/cance/save dialog to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
// Add the file size into the response header
Response.AddHeader("Content-Length", file.Length.ToString());
// Set the ContentType
Response.ContentType = ReturnExtension(file.Extension.ToLower());
// Write the file into the response
//Response.TransmitFile(file.FullName);
Response.WriteFile(file.FullName);
// End the response
Response.End();
}
else
{
this.Response.Write("Error in finding file. Please try again.");
this.Response.Flush();
}
}
catch (Exception ex)
{
this.Response.Write(string.Format("Error: {0}", ex.Message));
}
}
private string ReturnExtension(string fileExtension)
{
switch (fileExtension)
{
case ".htm":
case ".html":
case ".log":
return "text/HTML";
case ".txt":
return "text/plain";
case ".doc":
return "application/ms-word";
case ".tiff":
case ".tif":
return "image/tiff";
case ".asf":
return "video/x-ms-asf";
case ".avi":
return "video/avi";
case ".zip":
return "application/zip";
case ".xls":
case ".csv":
return "application/vnd.ms-excel";
case ".gif":
return "image/gif";
case ".jpg":
case "jpeg":
return "image/jpeg";
case ".bmp":
return "image/bmp";
case ".wav":
return "audio/wav";
case ".mp3":
return "audio/mpeg3";
case ".mpg":
case "mpeg":
return "video/mpeg";
case ".rtf":
return "application/rtf";
case ".asp":
return "text/asp";
case ".pdf":
return "application/pdf";
case ".fdf":
return "application/vnd.fdf";
case ".ppt":
return "application/mspowerpoint";
case ".dwg":
return "image/vnd.dwg";
case ".msg":
return "application/msoutlook";
case ".xml":
case ".sdxl":
return "application/xml";
case ".xdp":
return "application/vnd.adobe.xdp+xml";
case ".jar":
return "application/java-archive";
default:
return "application/octet-stream";
}
}
UPDATE :
나는 유형
case ".jar":
return "application/java-archive";
을 추가 그리고 그 문제가 해결되지 않았다. .jar 파일을 압축하면 정상적으로 전송할 수있었습니다.
필자가 다시 로컬 호스트를 테스트했을 때 파일이 아무 문제없이 다운로드되었음을 알았습니다. 그러나 내가 웹 서버에 그것을 밀어 때 문제가 얻을 때입니다.
TransmitFile은 더 큰 파일을 가진 서버에 친절합니다 : http://www.ddj.com/windows/202804466 – Kev
Kev - 그 링크에 대한 정보를 매우 고맙습니다! –