js Jquery字符UrlEncode 编码 C#(asp.net)解码 Server HttpUtility 区别 cookies存中文

时间:2023-12-27 12:54:37

一、Js asp.net 交互Url编码解码

C#(asp.net)编码:HttpUtility.UrlEncode(url)

Jquery解码:decodeURIComponent(url);

Jquery编码:encodeURIComponent(url);

C#(asp.net)解码:HttpUtility.UrlDecode

二、asp.net(Server HttpUtility)编码解码区别:

  HttpUtility.UrlEncode()默认是以UTF8对URL进行编码,而Server.UrlEncode()则以默认的编码对URL进行编码

三、cookies存中文

var cookieArray = document.cookie.split("; "); //得到分割的cookie名值对
var cookie = new Object();
for (var i = 0; i < cookieArray.length; i++) {
var arr = cookieArray[i].split("="); //将名和值分开
if (arr[0] == "UserSubscribe") userSubscribe=decodeURIComponent(arr[1]); //unescape乱码
}