我试图将值存储[email protected]&AFRSPASSWORD=%&v~lyHYNrTCcQq6
到中Cookies["AFRSSTATION"]
。该值已成功保存,我可以使用浏览器查看它。访问值时出现问题。当我尝试获得returningUser["AFRSUSERNAME"]
i的[email protected]
价值时,returningUser["AFRSPASSWORD"]
is的价值%
。看起来好像内部函数根据&
符号分割值。我的问题是如何保存&登录Cookie。给定波纹管是相关的代码
HttpCookie returningUser = null;
if (HttpContext.Current.Request.Cookies["AFRSSTATION"] != null)
{
returningUser = HttpContext.Current.Request.Cookies["AFRSSTATION"];
if (returningUser["AFRSUSERNAME"] != null &&
returningUser["AFRSUSERNAME"] != "" &&
returningUser["AFRSPASSWORD"] != null &&
returningUser["AFRSPASSWORD"] != "")
{
UserName = returningUser["AFRSUSERNAME"];
Password = returningUser["AFRSPASSWORD"];
Cookies并非允许所有字符,您可以使用Server.UrlEncode和UrlDecode方法来实现:
HttpCookie cookie = new HttpCookie("AFRSSTATION");
cookie.Values.Add("AFRSUSERNAME", Server.UrlEncode("[email protected]"));
cookie.Values.Add("AFRSPASSWORD", Server.UrlEncode("%&v~lyHYNrTCcQq6"));
Response.Cookies.Add(cookie);
//Retrieve Cookie values
UserName = Server.UrlDecode(returningUser["AFRSUSERNAME"]);
Password = Server.UrlDecode(returningUser["AFRSPASSWORD"]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句