1

我已经 Response.ContentType = "application/octet-stream";在 Downloads.aspx 页面的 Page_Load 处理程序中设置了 。当我尝试下载 .gif 文件时,它工作正常。但在 .jpg 文件的情况下,对话框显示文件类型为“application/octet-stream”,下载的文件只是一个不像预期的 .jpg 的文件。

4

1 回答 1

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
于 2012-08-08T19:12:01.103 回答