Response.Cookies[ "value" ].value and Request.Cookies[ "value" ].value query



我对cookie值有一些疑问。我有这个字符串"R&y1K2jwl:m;%nS0#pvd",我使用 Response.Cookie 将其传递给 cookieHttpContext.Current.Response.Cookies["_SecurityCode"]。值 = @"R&y1K2jwl:m;%nS0#pvd";

但是当我尝试使用它读取我的 cookie 的值时,HttpContext.Current.Request.Cookies["_SecurityCode"].值,我只得到"R&y1K2jwl:m"作为值。

你能帮我如何使用饼干获取整个字符串吗?

非常感谢。

根据我的不规则 %,; 等在 cookie 中是不允许的,因此文本被截断,如下面的帖子所示。http://www.daaq.net/old/javascript/index.php?page=writing+js+cookies&parent=js+cookies

在 ASP.Net 中,您可以使用System.Web.HttpUtility安全地对cookie进行编码,如下所示。

// Encode
HttpUtility.UrlEncode(cookieData);
// Decode
HttpUtility.UrlDecode(encodedCookieData);

最新更新