asp.net中的乱码问题

来源:互联网 发布:哪里买淘宝实名资料 编辑:程序博客网 时间:2024/05/05 22:46

 1.设置web.config文件

在其中加上如下代码:

< system.web>   
......   
< globalization requestEncoding="gb2312" responseEncoding="gb2312" culture="zh-CN" fileEncoding="gb2312" />   
......   
< /system.web>

2.下载文件时指定文件名,中文的文件名出现了乱码?

  使用Response.AddHeader("Content-Disposition", "attachment; filename="+HttpUtility.UrlEncoding(filename.ToString ()));进行处理。

3、传递中文之前,将要传递的中文参数进行编码,在接收时再进行解码。

 >> 进行传递

string Name = "中文参数";   
Response.Redirect("B.aspx?Name="+Server.UrlEncode(Name));//进行编码  

  >> 进行接收

string Name = Request.QueryString["Name"];   
Response.Write(Server.UrlDecode(Name));//进行解码

原创粉丝点击