I am trying to store the value [email protected]&AFRSPASSWORD=%&v~lyHYNrTCcQq6 into Cookies["AFRSSTATION"]. The value is saved successfully and i can see it using browser. Problem in accessing the values. When i try to get the value of returningUser["AFRSUSERNAME"] i got [email protected] and value of returningUser["AFRSPASSWORD"] is %. It looks like internal function spliting the value on the bases of & sign. My question is how can i save the & sign in Cookie. Given bellow is related code
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"];
Not all characters are allowed in Cookies, you can use Server.UrlEncode and UrlDecode methods to achieve this:-
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"]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With