对文件名使用UTF8编码,代码如下:
[HttpGet]
public ActionResult FileDown(Int64 id)
{
Order entity = bll.GetModel(id);
string contentType = "application/x-jpg";
if (System.IO.Path.GetExtension(entity.OFileName).ToLower().Equals(".bmp"))
{
contentType = "application/x-bmp";
}
else if (System.IO.Path.GetExtension(entity.OFileName).ToLower().Equals(".pdf"))
{
contentType = "application/pdf";
}
else if (System.IO.Path.GetExtension(entity.OFileName).ToLower().Equals(".doc"))
{
contentType = "application/msword";
}
//火狐浏览器不需要转换fileName,否则中文文件名易出现乱码
if (Request.ServerVariables["http_user_agent"].ToLower().IndexOf("firefox") == -1)
{
entity.OFileName = System.Web.HttpUtility.UrlEncode(entity.OFileName, System.Text.Encoding.UTF8);
}
return File(entity.OrderFile, contentType, entity.OFileName);
}