Chris Westbrook
Chris Westbrook

Reputation: 2100

; in cookie value trims cookie in asp.net

I am saving a cookie using a value from a database and then accessing that cookie on another page. i noticed that if the cookie has a ; in it's value, it is cut off at that ;. How do I fix this other than changing the data so it does not include ;?

Upvotes: 1

Views: 187

Answers (2)

John Rasch
John Rasch

Reputation: 63465

Semi-colons are special characters when it comes to cookies. You'll have to encode its value in the cookie somehow.

Since you're using ASP.NET, it should be as easy as calling:

cookieString = HttpUtility.UrlEncode(cookieString);

Upvotes: 1

Daniel A. White
Daniel A. White

Reputation: 190976

That is a limitation of http. You will have to encode the cookie value like this

string cookieValue = Server.UrlEncode(someValue);

and decoding is

string someValue = Server.UrlDecode(cookieValue);

Upvotes: 1

Related Questions