Strange problem with cookies in Safari and Asp.net

前端 未结 1 572
盖世英雄少女心
盖世英雄少女心 2020-12-14 13:19

I have a strange problem on my login page in Asp.net this problem only happens with Safari.

When the user is validated I fetch the name of the user from the database

相关标签:
1条回答
  • 2020-12-14 13:42

    Safari will not set cookies with non-ASCII characters in their value and other browsers can be unpredictable in how they display non-ASCII characters. As semi-colon is also not allowed in cookie values for any browser I would recommend using UrlEncode/UrlDecode.

    If you are just writing the cookie and do not have control over the site reading/displaying the value to put in the URLDecode you can also do something like this:

    ckCookie.Value = (Server.HtmlEncode( strSpecialCharacters )).Replace(";","");
    

    This will ensure the full string is set in the cookie and Safari, Chrome, Firefox and IE will still recognize the html codes even without the ; and does not require decoding when read.

    For a longer answer on cookie specs see: Allowed characters in cookies

    0 讨论(0)
提交回复
热议问题