1.通过web.config来解决
<system.web>
<globalization requestEncoding='"gb2312" response/encoding='gb2312" culture="zh-cn" fileEncoding="gb2312"/>
</system.web>
2.通过设置Aspx页面,在head中知道ASPnet同页面请求的编码
<head runat="server">
<title></title>
<meta http-equiv="Content_type" content="text/html; charset=gb2312">
</head>
3.在传递中文之前,对将要传递的中文参数进行编码,在接受时进行解码
编码方式1. HttpUtility.UrlEncode
是前台的方法:
<asp:HyperLink ID="Hyper" runat="server"
NavigateUrl='<%#"b.aspx?name"+httpuility.UrlEncode("中国人",System.Text.Encoding.GetEncoding("GB2312")) %>'
传递给b
</asp:HyperLink>
编码方式二、;Server.UrlEncode
是后台的方法:
string name = "中国人";
Response.Redirect("b.aspx?name=" + Server.UrlEncode(name));
编码方式三:JavaScript编码传输
function GoUrl()
{
var name="中国人";
location.href="B.aspx?name="+escape(name);
}
接受传过来的值
if(Request["name"]!=null)
{
string name=Request["Parm1"];
Response.Write(Server.UrlEncode(name));
}
一般来说设置web.config就行了,如果你用JavaScript调用webservice的话,web.config设置就无效了
4.让机器支持中文
一:如果上述方法都没弄好的话,就将页面用记事本打开,选择UTF_8作为编码方式,而不是默认的Ansi
二:打开注册表,确保HkEY_LOCAL_MACHINNE/System/CurrentControlSet/Services/Intinfo/Parameters/FavorDBCS的值为0
三:修改改数值后,必须运行IISRESET以重启IIS服务。