Safari Cookie Set Chinese failed

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.