asp. net Cookie value Chinese scrambled code problem solution
- 2020-05-24 05:30:56
- OfStack
Chinese cannot be written in cookie because of the innate encoding of cookie. So you need an intermediate code to make the transition. URLEncode is the best option.
We take asp.net as an example. The code is as follows:
When setting Cookie:
Note: encoding and decoding should be 1
We take asp.net as an example. The code is as follows:
When setting Cookie:
HttpCookie cookie = new HttpCookie("name", System.Web.HttpContext.Current.Server.UrlEncode(" The home of the script "));
Response.Cookies.Add(cookie); read Cookie When:
if (Request.Cookies["name"] != null)
{
Response.Write(System.Web.HttpContext.Current.Server.UrlDecode(Request.Cookies["name"].Value));
}
Note: encoding and decoding should be 1
System.Web.HttpContext.Current.Server.UrlDecode and System.Web.HttpContext.Current.Server.UrlEncode
System.Web.HttpUtility.UrlDecode and System.Web.HttpUtility.UrlEncode