在ASP.NET中,文件在Firefox中传输的方式是否不同?
我正在使用ASP.NET传输.jar文件。这段代码在IE上运行得很好。但是在Firefox上,文件下载时会损坏。最好的解决方法是什么?下面是我正在使用的代码在ASP.NET中,文件在Firefox中传输的方式是否不同?,asp.net,firefox,file,Asp.net,Firefox,File,我正在使用ASP.NET传输.jar文件。这段代码在IE上运行得很好。但是在Firefox上,文件下载时会损坏。最好的解决方法是什么?下面是我正在使用的代码 private void TransferFile() { try { string filePath = Server.MapPath("SomeJarFIle.jar"); FileInfo file = new FileInfo(filePath); if (file
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";
}
}
更新:
我添加了类型
case ".jar":
return "application/java-archive";
但这并没有解决问题。如果我压缩.jar文件,它就可以很好地传输
我确实注意到,当我再次测试本地主机时,该文件下载时没有任何问题。然而,当我把它推到web服务器上时,就是我遇到问题的时候。我认为在ReturnExtension函数中没有.jar的情况,我认为命名为ReturnMimetype可能更好。这可能是问题所在,还是你忘了粘贴 jar的mimetype应该是application/java归档文件。详情如下:
我认为这就是问题所在。我记得当我传输一个.docx文件时遇到了同样的问题,它实际上是一个具有不同扩展名的zip文件,作为一个.jar文件。下载在IE中运行良好,但Firefox破坏了它。解决方案是发送正确的mimetype。我认为在ReturnExtension函数中没有.jar的例子,我认为最好使用ReturnMimetype。这可能是问题所在,还是你忘了粘贴 jar的mimetype应该是application/java归档文件。详情如下:
我认为这就是问题所在。我记得当我传输一个.docx文件时遇到了同样的问题,它实际上是一个具有不同扩展名的zip文件,作为一个.jar文件。下载在IE中运行良好,但Firefox破坏了它。解决方案是发送正确的mime类型。我只看到两件事,您似乎没有.jar文件扩展名的mime类型
两个我个人使用writefile而不是transmit,但我不确定两者的区别。我只看到两件事,似乎您没有.jar文件扩展名的mime类型
我个人使用writefile而不是transmit,但我不确定两者的区别。使用Response.writefile或Response.BinaryWrite,TransmitFile方法存在一些已知的奇怪行为 使用Response.WriteFile或Response.BinaryWrite,TransmitFile方法存在一些已知的奇怪行为 TransmitFile对文件较大的服务器更友好:TransmitFile对文件较大的服务器更友好:是否有机会链接记录这些已知的奇怪行为?在谷歌上快速搜索并没有找到任何相关信息。@ckittel——不知道它是否仍然适用——是很久以前的事了。我只记得在大量搜索的长尾中找到了它,我遇到的类似问题通过删除TransmitFile得到了解决。有没有可能找到记录这些已知奇怪行为的链接?在谷歌上快速搜索并没有找到任何相关信息。@ckittel——不知道它是否仍然适用——是很久以前的事了。我只记得在大量搜索的长尾中找到它,而我遇到的类似问题通过删除TransmitFile得到了解决。