方案一:web.cofig统一编码
<globalization requestEncoding="" responseEncoding=""/>
方案二:使用HttpUtility指定编码解码。
HttpUtility.UrlEncode(Request.RawUrl, Encoding.GetEncoding("GB2312")); HttpUtility.UrlDecode(Request["k"],Encoding.GetEncoding("GB2312"))
Ajax中文乱码处理:(http://blog.sina.com.cn/s/blog_742fa84001010f42.html)
加密:test.aspx?parent=encodeURIComponent("你好吗?"); // "你好吗?" 加密后:"%u4f60%u597d%u5417%uff1f"
解密:var ret = decodeURIComponent("%u4f60%u597d%u5417%uff1f");
Aspx:
解密:string de = Server.UrlDecode(Request.QueryString["parent"]); // 解密后:de = "你好吗?"
返回加密:Response.Write("我很好!");
edit121216:
传参时进行编码:search.aspx?k=" + escape(txtkw.val());
如果是服务器端调用js传参可以用:HttpUtility.UrlEncode(Request["k"]);
最后使用时再进行解码:HttpUtility.UrlDecode(Request["k"]);
浙公网安备 33010602011771号