在Cookie中保存“&”符号

维杰·拉娜(Vijay Rana)

我试图将值存储[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"];
拉胡尔·辛格(Rahul Singh)

Cookies并非允许所有字符,您可以使用Server.UrlEncodeUrlDecode方法来实现:

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章