var rep = new HttpResponseMessage(HttpStatusCode.OK);
rep.Content = new StreamContent(stream);
var disPosition = new ContentDispositionHeaderValue("attachment");
rep.Content.Headers.ContentType = new MediaTypeHeaderValue(application/octet-stream);
var userAgent = Request.Headers.UserAgent.ToString().ToUpper();
//IE浏览器文件名乱码处理
if (!string.IsNullOrEmpty(res.Obj?.FileName))
{
string filename = res.Obj.FileName;
if (userAgent.Contains("MSIE") || userAgent.Contains("TRIDENT") || userAgent.Contains("EDGE"))
{
disPosition.FileName = System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);
disPosition.Name = System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);
disPosition.Size = (long)filename.Length;
}
else
{
disPosition.FileName = filename;
disPosition.Name = filename;
disPosition.Size = (long)filename.Length;
}
rep.Content.Headers.ContentDisposition = disPosition;
}
IE浏览器文件乱码
最新推荐文章于 2023-03-08 14:48:54 发布