1. 程式人生 > >關於.NET HttpCookie 中文亂碼問題

關於.NET HttpCookie 中文亂碼問題

sys esp value 解碼 enc default logs tostring system


HttpCookie Cookie = new HttpCookie("Shop");

//服務端存入Cookie前先進行編碼
Cookie.Values.Add(ShopId,HttpUtility.UrlEncode(ShopInformation, System.Text.Encoding.Default));
Cookie.Expires = DateTime.Now.AddMinutes(20);
Response.Cookies.Add(Cookie);

//客戶端讀取 按編碼的格式進行解碼

var Shop = Request.Cookies["Shop"][Key].ToString();
Shop = HttpUtility.UrlDecode(Shop,System.Text.Encoding.Default);
var ShopData = Shop.Split(‘,‘);

技術分享

關於.NET HttpCookie 中文亂碼問題