asp.net和饼干特殊字符 [英] asp.net and cookies special characters

查看:195
本文介绍了asp.net和饼干特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有发现很有趣的问题,asp.net与饼干:
加入像测试&安培值的cookie时;
使用

Have found very interesting issue in asp.net with cookies: when adding cookie with value like test& using

HttpCookie cookie = new HttpCookie("test", "test&");
Response.Cookies.Add(cookie);

,然后试图找回价值Request.Cookies时[测试]尾随符号都将丢失。如果没有拖尾它不会丢失。在Firebug或JavaScript的数据是正确的,因此是asp.net具体的我想。
当然,大多可以说只使用UrlEn code。这是不是真的有必要吗?是否有饼干章程不允许任何列表(因为我觉得它比针对URL小)?
我也发现了类似的话题,但没有和放大器;符号的Restricted list:
在cookie中允许的字符

推荐答案

&是在cookie中不是允许的字符。这是必要的EN code用的 UrlEn code 方法。

The ampersand is not an allowed character in a cookie. It's necessary to encode the cookie data with the UrlEncode method.

System.Web.HttpUtility.UrlEncode(cookie);

也看到这些做题/答案:

See also these SO questions/answers:

  • Broken string in cookie after ampersand (javascript)
  • How do you use an Ampersand in an HTTPCookie in VB.NET?

这篇关于asp.net和饼干特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆