js Jquery字元UrlEncode 編碼 C#(asp.net)解碼 Server HttpUtility 區別 cookies存中文

weixin_34391854發表於2017-02-27

一、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亂碼
}

相關文章