0

Other browsers are giving the results as expected but the problem is only with Safari. When we have a french text like Créer it does not store the value in the cookie.

Step 01

Storing the values in cookie as follow

CookieStudent.Values["FirstName"] = newApplicant.FirstName;
CookieStudent.Values["LastName"] = newApplicant.LastName; 
CookieStudent.Values["Email"] = newApplicant.Email;
CookieStudent.Values["BirthDate"] = newApplicant.DateOfBirth;
Response.Cookies.Add(CookieStudent);

Step 02

Getting the stored cookie value from another controller.

if (!string.IsNullOrWhiteSpace(CookieStudent.Values["FirstName"]))
{
   newApplicant.FirstName = CookieStudent.Values["FirstName"];
}
if (!string.IsNullOrWhiteSpace(CookieStudent.Values["LastName"])) 
{
   newApplicant.LastName = CookieStudent.Values["LastName"];
}
if (!string.IsNullOrWhiteSpace(CookieStudent.Values["Email"]))
{
   newApplicant.Email = CookieStudent.Values["Email"];
}
if (!string.IsNullOrWhiteSpace(CookieStudent.Values["BirthDate"]))
{
   newApplicant.DateOfBirth = CookieStudent.Values["BirthDate"];
}

Note : This solution was not working for me Server.HtmlEncode(newApplicant.FirstName); or HttpUtility.UrlEncode(newApplicant.FirstName); and then corresponding decode

Arshath Shameer
  • 453
  • 4
  • 15
  • Please show us how `CookieStudent` is declared. Also, please include a screenshot of your cookie values (something like https://www.macobserver.com/tmo/article/see_full_cookie_details_in_safari_5.1 ). – mjwills Aug 01 '17 at 12:06
  • have you check with Creer without the accent on the e? – Cedric Royer-Bertrand Aug 01 '17 at 12:47
  • Can you show us what you used to decode after using `HttpUtility.UrlEncode`? – mjwills Aug 01 '17 at 13:10
  • @CedricRoyer-Bertrand I can not prevent that. Yes it works without that accent in Safari but this is a site which supports English and French so when it comes to french there are situations where these kind of accents are in use. – Arshath Shameer Aug 02 '17 at 03:27
  • @mjwills This is how decode is done. HttpUtility.UrlDecode(CookieStudent.Values["FirstName"]); – Arshath Shameer Aug 02 '17 at 03:29
  • `HttpUtility.UrlEncode` and `HttpUtility.UrlDecode` should work. Can you show us a screenshot of your cookie values when you use that? – mjwills Aug 02 '17 at 04:58
  • @mjwills Finally HttpUtility.UrlEncode and HttpUtility.UrlDecode worked for me in Safari. – Arshath Shameer Aug 04 '17 at 12:26

2 Answers2

1

These two changes resolved the problem with Safari browser for french characters

For Encode HttpUtility.UrlEncode(newApplicant.FirstName); and for decode HttpUtility.UrlDecode(CookieStudent.Values["FirstName"]);

Arshath Shameer
  • 453
  • 4
  • 15
0

According to this thread allowed character in cookies it could be because of the é. Try maybe to not use accent in your code, and only use them when you want to display something for the user.