using _ in cookie names

K

Kevin Blount

I have an existing site that's being update from ASP to ASP.NET (C#).
The site uses cookies and I've having trouble reading them.

For example, one Cookie created using ASP was "member_id", and using
ASP I simply get the value using 'request.cookies("member_id")'

However, using C# I have to replace '_' with '%5F' or it won't get
read, i.e.

string tempVar = Request.Cookies["member%5Fid"]

is this expected, or is there a way to locate the cookie more easily,
i.e. with the underscore character?

tia
 
G

Guest

Kevin,
not to sound blunt but, why not just avoid using problematic cookie names in
the first place?
Peter
 
K

Kevin Blount

As previously stated, this is an existing site that's being updated, so
I have to use and cater for cookies created by that existing site.
Obviously I can't go to all previous visitors to our site and
rename/update their cookies, so I have to use existing cookies with _
char in them..

now that we're over that.. any ideas?
Kevin,
not to sound blunt but, why not just avoid using problematic cookie names in
the first place?
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Kevin Blount said:
I have an existing site that's being update from ASP to ASP.NET (C#).
The site uses cookies and I've having trouble reading them.

For example, one Cookie created using ASP was "member_id", and using
ASP I simply get the value using 'request.cookies("member_id")'

However, using C# I have to replace '_' with '%5F' or it won't get
read, i.e.

string tempVar = Request.Cookies["member%5Fid"]

is this expected, or is there a way to locate the cookie more easily,
i.e. with the underscore character?

tia
 
K

Kevin Blount

Good call, but unfortunately that didn't work. Thanks for the idea
though
Can you use [@"member_id"] ???

Sa


Kevin Blount said:
I have an existing site that's being update from ASP to ASP.NET (C#).
The site uses cookies and I've having trouble reading them.

For example, one Cookie created using ASP was "member_id", and using
ASP I simply get the value using 'request.cookies("member_id")'

However, using C# I have to replace '_' with '%5F' or it won't get
read, i.e.

string tempVar = Request.Cookies["member%5Fid"]

is this expected, or is there a way to locate the cookie more easily,
i.e. with the underscore character?

tia
 
M

Martin Carpella

Kevin Blount said:
string tempVar = Request.Cookies["member%5Fid"]

I suppose that the Cookie-names are not URL-decoded.

You could write it a little bit more readable by using
string tempVar = Rquest.Cookies[Server.UrlEncode("member_id")];

Best regards,
Martin
 
K

Kevin Blount

Martin said:
string tempVar = Rquest.Cookies[Server.UrlEncode("member_id")];

Unfortunately that didn't work either, Martin, but it's around where I
was looking. I just tried using Server.HtmlEncode as well, but neither
return the value of the that cookie.

Oh well..going forward I will be using .NET friendly names, but I'll
have to have to stick with %2f for existing ones.

Thanks for trying all.
 
M

Martin Carpella

Kevin Blount said:
Martin said:
string tempVar = Rquest.Cookies[Server.UrlEncode("member_id")];

Unfortunately that didn't work either, Martin, but it's around where I
was looking. I just tried using Server.HtmlEncode as well, but neither
return the value of the that cookie.

Oh, I see, Server.UrlEncode seems to return lower-case characters, while
you are needing upper case... Sorry, missed that one.

Best regards,
Martin
 

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

Top