Tuesday, March 13, 2012

Session variables and extended ASCII chars?

I am using session variables to store the currently logged in user's username.. and it's worked great so far, however, when someone has any sort of "extended" ASCII in their username, like "ã", etc. -- the session variable gets returned with extra characters next to the extended character. Very strange behavior.

I've tried searching the web for info. on the restrictions of session variables, and if they're somehow limited to the very basic alphanumeric set, but have come up empty.

Does anyone have any thoughts on this? I'm stuck here, and any help would be appreciated.

Thanks!do you have a code example, I tried to reproduce the behavior and it worked correctly for me.


Session("blah") = "ã"
Dim xyz As String = CStr(Session("blah"))
Dim abc As String = Session("blah")

both xyz and abc = "ã" after I ran this. I also tried to see if there would be any difference between using a type converter, and letting .net figure out what to do with the contents of the session.
Doh, you're right. It's been a crazy morning. It's actually COOKIES I'm having trouble with. I'm doing this to store the cookie:

Dim Cookie As HttpCookie
Cookie = New HttpCookie("MyUserName", "Äpb")
Cookie.Expires = Now.AddDays(1)
Cookie.Secure = False
Response.Cookies.Add(Cookie)

Cookie = New HttpCookie("MyPassword", "testpassword")
Cookie.Expires = Now.AddDays(1)
Cookie.Secure = False
Response.Cookies.Add(Cookie)

But when I go to read it back:

Request.Cookies("MyUserName").Value.ToString

I'm getting this back instead:

+äpb
I still didn't have a problem with that exact code, I'd start to look past asp.net on this one, perhaps the cookie is getting changed somehow after you set it. I really don't know, seems very odd indeed!

0 comments:

Post a Comment