在URL中传递中文的解决方案
之前做一个功能需要在url上传递中文的参数值,整理了一下,方便日后参考
解决方法:
1.通过设置web.config指定ASP.NET应用程序默认的请求和响应的编码。
<System.web>
<globalization requestEncoding="gb2312" responseEnding="gb2312" Cultrue="zh-CN" fileEncoding="gb2312" />
</System.web>
2.通过Aspx页面head指定ASP.NET页面的请求和响应编码。
<head runat="server">
<title></title>
<meta http-equiv="Content-Type" content="text/html" charset="gb2312">
</head>
3.在传递中文前,对传递的中文参数进行编码,在接收时解码。
编码方式一:HttpUtility.UrlEncode
编码方式二:Server.UrlEncode
解码:Server.UrlDecode("参数名");


浙公网安备 33010602011771号