Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 5th, 2004, 04:53 AM
Registered User
 
Join Date: Jan 2004
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
 
Old July 5th, 2004, 08:52 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old July 5th, 2004, 09:54 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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?
 
Old July 7th, 2004, 01:10 AM
Registered User
 
Join Date: Jan 2004
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?
 
Old July 7th, 2004, 02:34 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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?





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.