-1)//IE浏览器{context.Response.AddHeader(" ;小李飞刀资源网更新日期:2024/10/11.">

下载文件个别浏览器文件名乱码解决办法

网络编程 发布日期:2024/10/11 浏览次数:1

正在浏览:下载文件个别浏览器文件名乱码解决办法
复制代码 代码如下:
    if (context.Request.UserAgent.ToLower().IndexOf("msie", System.StringComparison.Ordinal) > -1)//IE浏览器
 {
     context.Response.AddHeader("content-disposition", "filename=" + HttpUtility.UrlEncode(fileName));
 }
 if (context.Request.UserAgent.ToLower().IndexOf("firefox", System.StringComparison.Ordinal) > -1)//firefox浏览器
 {
     context.Response.AddHeader("content-disposition", "attachment;filename=\"" + fileName + "\"");
 }
 else//其他浏览器
 {
     context.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
 }
 context.Response.ContentType = "application/x-xls";