博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

解决ie和firefox中的保存文件名乱码问题

Posted on 2012-09-03 14:32  oilsun  阅读(424)  评论(0编辑  收藏  举报

一.使用ajax与服务器交互 不管是post方式还是get方式都应该对中文进行编码 只有这样 服务器端(ie浏览器 firefox不用)才能正确解析汉字 否则就是乱码。

二.在asp.net MVC中 ie跟firefox对下载文件名的处理不同

    / ie通过编码实现正确的文件名/

   public FileContentResult DownLoad()
        {
            string temp = "我是中国人!";
            return File(System.Text.Encoding.UTF8.GetBytes(temp), "text/plain",Url.Encode("中国.txt"));
        }


    /firefox不必编码否则出现编码后的文件名/

   public FileContentResult DownLoad()
        {
            string temp = "我是中国人!";
            return File(System.Text.Encoding.UTF8.GetBytes(temp), "text/plain","中国.txt");
        }

兼容firefox跟ie的做法

通过Request.Browser.Browser.ToUpper()来判断是ie还是firefox