我在Downloads.aspx页面的Page_Load处理程序中设置了Response.ContentType = "application/octet-stream";
。当我尝试下载.gif文件时,它工作正常。但是在.jpg文件的情况下,对话框显示文件类型为“application / octet-stream”,下载的文件只是一个非预期的.jpg文件。
答案 0 :(得分:4)
尝试为每种文件类型设置显式内容类型。
switch (fileExtension)
{
case "gif": Response.ContentType = "image/gif"; break;
case "jpeg": Response.ContentType = "image/jpg"; break;
case "jpg": Response.ContentType = "image/jpg"; break;
case "png": Response.ContentType = "image/png"; break;
default: Response.ContentType = "application/octet-stream"; break;
}
请参阅以下mime类型参考链接:
http://www.freeformatter.com/mime-types-list.html
https://github.com/cymen/ApacheMimeTypesToDotNet/blob/master/ApacheMimeTypes.cs