Safari Cookie Set Chinese failed resolution _ios

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 handset test, when the function is basically completed, the original on the Android operation of the normal application, Running on iOS, there are a lot of strange problems, according to the troubleshooting, found that because the cookie did not get the value of the relevant information can not be obtained.

First thought is a cookie Chinese garbled problem, and later tracked found that the value of the cookie was not assigned to success, online search data, found that Safari does not allow non-ASCII encoded values, in other words: Chinese storage is not allowed.

To solve this problem, you must encode the cookie value and then decode it when the value is taken.

Back-end settings cookies with the ASP.net, the front-end to obtain the use of JavaScript, their encoding and decoding can be consistent? You can only try it now:

Several methods were tried, and the Httputility.urlencode () was found to be successful in encoding:

cookie = new HttpCookie ("Rdname");  
Cookie. Value = Httputility.urlencode (user. Registerdeptname);  
Cookie. Expires = System.DateTime.Now.AddDays ();  
Context. Response.Cookies.Set (cookie);  

Client JavaScript is decoded as:

var deptname = Cookie (' Rdname ');  
Deptname= decodeuricomponent (deptname);  
$ ("#pickerlb"). Val (Deptname);  

That is, the decodeuricomponent () and C # Httputility.urlencode () in JavaScript are paired.

This safari cookie set Chinese failure to solve the problem is to share the whole of the content of everyone, hope to give you a reference, but also hope that we support the cloud habitat community.

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.