其他浏览器正在按预期给出结果,但问题仅出在Safari上。 当我们有像Créer这样的法语文本时,它不会将值存储在 cookie 中。
步骤 01
将值存储在 cookie 中,如下所示
CookieStudent.Values["FirstName"] = newApplicant.FirstName;
CookieStudent.Values["LastName"] = newApplicant.LastName;
CookieStudent.Values["Email"] = newApplicant.Email;
CookieStudent.Values["BirthDate"] = newApplicant.DateOfBirth;
Response.Cookies.Add(CookieStudent);
步骤 02
从另一个控制器获取存储的 cookie 值。
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"];
}
注意:此解决方案对我不起作用Server.HtmlEncode(newApplicant.FirstName); or HttpUtility.UrlEncode(newApplicant.FirstName); and then corresponding decode
这两个更改解决了 Safari 浏览器的法语字符问题
对于编码HttpUtility.UrlEncode(newApplicant.FirstName);
并用于解码HttpUtility.UrlDecode(CookieStudent.Values["FirstName"]);
根据这个线程允许的cookie字符,这可能是因为é。尽量不要在代码中使用重音,并且仅在要向用户显示某些内容时才使用它们。