Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Retrieving cookie values from classic ASP


Message #1 by Imar@S... on Sun, 21 Apr 2002 17:55:07
Well, I found a solution, thanks to Alex Shiell who replied to a previous 
message in september 2001 with a similar problem.
http://p2p.wrox.com/archive/proasp_codeclinic/2001-09/21.asp

I ended up replacing each character with its ASC value, separating them 
with a -, like this:

[Classic ASP]
Function convertCharsToEntities(s)
	Dim i, c
	for i = 0 to (len(s) -1)
		If i > 0 then
			c = c & "-"
		end if 
		c = c & (Asc(Mid(s, i+1, 1)))
	Next
	convertCharsToEntities = c
End Function


Then, in ASP.NET I rebuilt the string like this:

Dim arrChars() As String
Dim sResult As String
Dim sCookie As String
sCookie = UrlDecode(Request.Cookies("SessionKey").Value.ToString())
arrChars = Split(sCookie, "-")
Dim i As Integer
For i = 0 To (UBound(arrChars) - 1)
    sResult &= Chr(arrChars(i))
Next

And there you have it, sResult now contains my original string.

It has to be optimized a little, maybe using reg exps as Alex showed, but 
at least it's quick fix and works.


Imar









> Hi Peter,

> Thanks for your reply. Yeah, I could successfully pass ordinary data 
l> ike "FORM 123" without a problem. Spaces in the values ended up escaped 
a> utomagically.

> I looked at the way my cookies are stored in the cookie file. When I use 
E> scape, the value seems to be escaped twice. When I skip the Escape 
m> ethod, the values are still escaped. So when I use Escape(sSessionKey) 
it 
t> urns out as:

>      %25C1

> instead of 

>      %C1

> But when I don't use Escape, I still get %C1 etc instead of ÁÊPàÕ#ó?¡

> I know the other methods shouldn't make a difference, but after a while 
y> ou start trying everything that might help ;-)

> Is there another way to store invalid characters in a cookie? I can't 
c> ontrol the output of the encrypt function, so I have to deal with this 
m> essed up string somehow. However, I can control both the classic ASP as 
t> he ASP.NET app, so other solutions / suggestions are welcome as well.

> A while ago I had a similar problem with this type of strings. Someone 
s> uggested a custom made solution that replaced each character in the 
s> tring with a number, if I recall correctly. It may turn out that that 
is 
t> he only way to go..........

> 
I> mar

> 


  Return to Index