Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 5th, 2004, 04:53 AM
Registered User
 
Join Date: Jan 2004
Location: London, , United Kingdom.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Accessing .asp cookie from ASP.net

I have encrypted and storing a string in cookie in .asp page. When I access this .asp cookie and decrypt it back in ASP.net page, I am not getting the original string. But if I I access this .asp cookie and decrypt it back in a .asp page, I am getting the original string, what is it so?


Thanks and Regards
Reply With Quote
  #2 (permalink)  
Old July 5th, 2004, 08:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

If you are getting a different string, can you verify that the algorithms are the same? They probably are using a slighly different algorithm. If you can't get that to work, I would consider using a component to do the encrypt/decrypt. That way, both ASP and ASP.NET could use the same component.

Brian
Reply With Quote
  #3 (permalink)  
Old July 5th, 2004, 09:54 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Can you confirm that you are actually getting the cookie value back, apart from the encryption/decryption?
Reply With Quote
  #4 (permalink)  
Old July 7th, 2004, 01:10 AM
Registered User
 
Join Date: Jan 2004
Location: London, , United Kingdom.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When i am retrieving the encrypted value stored in a ASP cookie in a ASP.net page using HTTPCookie, i am getting a different encrypted value in ASP.net compared to the encrypted value stored in a ASP cookie in a ASP page.

does not the HttpCookie in ASP.net store the special characters?? Is it so?
Reply With Quote
  #5 (permalink)  
Old July 7th, 2004, 02:34 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

I ran into this issue a long time ago as well. Here's how I fixed it.

In classic ASP, set cookies like this:
Code:
  Response.Cookies("MYNetCookie") = ConvertCharsToEntities ("YourValue")

  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 .NET you can get the cookies value like this:
Code:
  MyCookieString = UrlDecode(Request.Cookies("MYNetCookie").Value.ToString())
Code:
  ' Split to array with all asc codes
  arrMyValue = Split(MyCookieString, "-")

  Dim i As Integer = 0
  For i = 0 To ((arrMyValue.Length) - 1)
      MyCookieValue &= Chr(arrMyValue(i))
  Next

  ' At this point, MyCookieValue should contain the initial string
Basically what this does is convert each character in your original string to its associated numeric value. Then this long string of numbers (separated by a dash) is stored as the cookie's value.
In .NET the reversed process takes place: The cookie value is split on the dash, and each number is used to retrieve its associated string value to return the original string.

I can't really recall what the problem was, but I can imagine it has something to do with the way the cookie is sent as plain text or unicode. With "normal", low ascii values there is usually not a problem, but encrypted strings often contain a lot of weird characters.

This code is over 3 years old, so it may fix a problem that no longer exists in .NET 1.1 or 1.0 with a service pack. But it's worth a try.....

Hope this helps, and if it does, can you let me know?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Hyper chondriac music by Muse (Track 10 from the album: Hullabaloo) What's This?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Word through ASP.NET renoldr General .NET 2 December 2nd, 2013 06:58 AM
accessing files from asp.net naidukap ASP.NET 1.0 and 1.1 Professional 1 November 18th, 2005 08:59 AM
Cookie Updating in ASP.NET br_r14 Classic ASP Basics 1 May 5th, 2005 06:55 PM
Accessing ASP Application Object from .NET yuvalk ASP.NET 1.x and 2.0 Application Design 2 July 19th, 2004 10:29 AM
Cookie btw. ASP and .NET collie VB.NET 2002/2003 Basics 5 November 10th, 2003 09:38 AM



All times are GMT -4. The time now is 01:42 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.