我写的asp.net下的一个下载程序,提供下载的文件有很多是中文名称,在论坛里也看了很多帖子,慢慢地也完成了,就是用windows自带的下载程序下载完全没有问题,但是只要用下载工具比如flashget、IDM等可以下载但文件名为乱码。我的代码如下:
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename="+filename);
后一句的filename已经对传过来的中文参数进行了编码:
filename=HttpUtility.UrlEncode(filename,Encoding.UTF8);
高人请帮忙!分数不够另开贴给!

解决方案 »

  1.   

    http://blog.csdn.net/goody9807/articles/138871.aspx
      

  2.   

    在你的web.config进行设置
     <globalization 
                requestEncoding="gb2312" 
                responseEncoding="gb2312" 
       />
      

  3.   

    把你的文件名给HttpUtility.UrlEncode(filename) 就行了~呵呵
      

  4.   

    to:楼上
    默认的编码方式是utf-8吧,我不是很熟悉,望指教
      

  5.   

    Response.ContentEncoding = System.Text.Encoding.DefaultResponse.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename="+filename);加一句
      

  6.   

    Response.ContentEncoding = System.Text.Encoding.Unicode;
      

  7.   

    对多种编码进行尝试,如goody980说的,是可以的。
      

  8.   

    为什么要那么麻烦呢?
    string strFilename=HttpUtility.UrlEncode(filename);
    Response.Redirect(strFilename);
      

  9.   

    falshget获得文件名的方法就是取Content-Disposition里的filename属性
      

  10.   

    to nickycheng(枪枪成):
    既然这样是“falshget获得文件名的方法就是取Content-Disposition里的filename属性”,那为什么用windows自带的下载程序就一切正常,用flashGet就乱码?
      

  11.   

    为什么要那么麻烦呢?
    string strFilename=HttpUtility.UrlEncode(filename);
    Response.Redirect(strFilename);
    写错了
    string strFilename=HttpUtility.UrlEncode(filename);
    Response.Redirect("http://yourdomain/"+strFilename));
    怕别人下载还可以进行路径过滤