Recently used H5 for mobile phone development, because it is the window operating system, in order to facilitate development and debugging, directly in the Chrome browser test, and then on the Android mobile phone-side test, when the basic completion of the original function on Android to run a normal application, When running on iOS, there are a number of strange problems, and according to the troubleshooting, it is found that the information is not available because the cookie has not been fetched.
At first, I thought it was a cookie in Chinese garbled problem, later tracking found that the value of the cookie has not been assigned success, the online search data, found that Safari does not allow non-ASCII encoded values, in other words: Do not allow Chinese storage.
To solve this problem, the cookie value must be encoded and then decoded when the value is set.
The backend set the cookie with the ASP. NET, the front-end access JavaScript, their encoding and decoding can be consistent? You can only try it at this moment:
Several methods were tried to find the successful encoding using Httputility.urlencode():
1 New HttpCookie ("rdname"); 2 Cookies. Value = httputility.urlencode (user. Registerdeptname); 3 Cookies. Expires = System.DateTime.Now.AddDays (+); 4 Context. Response.Cookies.Set (cookie);
Client JavaScript is decoded as:
1 var deptname = Cookie ('rdname'); 2 deptname= decodeuricomponent (deptname); 3 $ ("#pickerlb"). Val (Deptname);
That is: decodeURIComponent () and C # Httputility.urlencode() in JavaScript are paired.
Safari Cookie Set Chinese failed