JanMichael
JanMichael

Reputation: 31

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

I have some question regarding cookies value. I have this string "R&y1K2jwl:m;%nS0#pvd", I passed it to cookie using Response.Cookies HttpContext.Current.Response.Cookies["_SecurityCode"].Value = @"R&y1K2jwl:m;%nS0#pvd";

but when I'm trying to read the value of my cookie using this, HttpContext.Current.Request.Cookies["_SecurityCode"].Value, I only get "R&y1K2jwl:m" as a value.

Can you help me how to get the whole string using cookies??

Thank you so much.

Upvotes: 0

Views: 1291

Answers (1)

Robby Indian
Robby Indian

Reputation: 39

As per my unserstanding %,; etc are not allowed in cookies therefore the text is truncated as shown in below post. http://www.daaq.net/old/javascript/index.php?page=writing+js+cookies&parent=js+cookies

In ASP.Net you can use System.Web.HttpUtility to safely encode the cookie as below.

// Encode
HttpUtility.UrlEncode(cookieData);

// Decode
HttpUtility.UrlDecode(encodedCookieData);

Upvotes: 1

Related Questions