HttpCookie : adding value with special characters error

G

Guest

Hi all,

I'm having a strange problem using cookies, setting values with special
characters.

Set cookie data:
<snipet>
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName,
encryptedTicket);

authCookie.Values.Add("Displayname", strDisplayname);
authCookie.Values.Add("Email", strEmail);
Response.Cookies.Add(authCookie);
</snipet>


Read cookie data:
<snipet>
FormsAuthenticationTicket authTicket = null;
try {
authTicket = FormsAuthentication.Decrypt(authCookie.Values[0]);
}
catch (Exception exc)
{
return;
}
</snipet>

This code works fine, except if the "displayname" cookie pair value has some
special character, like the "&" char.

Then, only in the cookie reading part, it "blows away" with the exception:
"Invalid value for 'encryptedTicket' parameter."

After a while I discovered that this was due to the value of the
displayname, so I did the saving cookie value like this:

<snipet>
....
authCookie.Values.Add("Displayname", HttpUtility.UrlEncode(strDisplayname));
....
</snipet>

And it did the trick... so I thought...
This worked in my dev environment, but in the production environment it
still raises the same exception.

Any help would be appreciated.

Thanks in advanced

nMatos
PTSI
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top