Wednesday 19 March 2008

Error Saving a Query String to a Cookie

Here’s one to note. I have some code that saves the requested URL to a cookie and later retrieves it. The strange thing was that when retrieving the value, anything after an ampersand in the query string was lost. The solution was to encode the Url using UrlEncode() (not HtmlEncode()).

Response.Cookies["RequestedPage"].Values.Add("Url", HttpUtility.UrlEncode(value))

1 comment:

Colin said...

Aha! Great stuff, cheers, just bumped into this ourselves :)