I am creating cookie using jquery and I set value into it. when I am reading that value, it is coming as something like with %20, there spaces has been converted to some thing like that. so how can I get proper value.
here is my Cookie creation code :
$.cookie('ck_name', 'william smith', { path: '/' });
in razor, I am reading cookie like this :
Request.Cookies["ck_coursename"].Value.ToString()
Output is : willian%20smith
i tried both @html.raw() and httputility.htmlencode, but problem still persists.
any help ? can be appreciated.. thanks in advance.
It's perfectly acceptable, even if it's not strictly mandatory. There are only a handful of values that must be URL encoded, but just blanket URL encoding everything makes it much easier to work with cookies.
It is then base64 encoded so it is an ASCII string, since the underlying HTTP protocols expect to work with ASCII. That base64 encoded string becomes the value of the cookie. When cookies are sent back to the server, they are read, (base64) decoded, decrypted, JSON parsed, and stored in memory as key/value pairs.
The . NET Framework provides several classes for encoding (converting Unicode characters to a block of bytes in another encoding) and decoding (converting a block of bytes in another encoding to Unicode characters. The System.
The value is URL encoded, so you would use the UrlDecode
method to read it:
HttpUtility.UrlDecode(Request.Cookies["ck_coursename"].Value.ToString())
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