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
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