473,408 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Weird cookie problem

I'm writing a cookie in one asp.net page, then trying to read that new
value in another.

Problem is, the saved value disappears when the cookie code calls it!

Here's the code...

SETTING THE COOKIE
************************************************** *******
Dim i As String = Request.QueryString("passedVal").ToString
Dim aCookie As HttpCookie = Request.Cookies("MyCookie")
aCookie.Values("value1") = aCookie.Values("value1") + 1
aCookie.Values("value2") = aCookie.Values("value2").ToString & i & ";"
Response.Redirect("page2.aspx")
READING THE COOKIE
************************************************** ***********
Dim aCookie As HttpCookie = Request.Cookies("MyCourses")
Dim MyVal1 As Integer = aCookie.Values("value1")
Dim MyVal2 as String = aCookie.Values("value2")
No matter what I do, MyVal2 is always a zero-length string (""). I am
expecting somthing like "1;2;3;4;" depending upon user input. The
values should get tacked on the end.

But it just aint workin!!!!

I've tested this on several machine, different browsers the result is
the same. Values set in page1 are gone when page2 trys to read it.

HELP!!!

Sep 10 '06 #1
2 1416
Hi,

Todd wrote:
I'm writing a cookie in one asp.net page, then trying to read that new
value in another.

Problem is, the saved value disappears when the cookie code calls it!

Here's the code...

SETTING THE COOKIE
************************************************** *******
Dim i As String = Request.QueryString("passedVal").ToString
Dim aCookie As HttpCookie = Request.Cookies("MyCookie")
aCookie.Values("value1") = aCookie.Values("value1") + 1
aCookie.Values("value2") = aCookie.Values("value2").ToString & i & ";"
Response.Redirect("page2.aspx")
You are getting an array from the request, and then modify the array's
values. However, if you want to pass the cookies to the browser (where
they will be stored), you must write them using Response.Cookies.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Sep 10 '06 #2
Thanks.....that worked. Brain unplugged!!

Sep 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: zorro | last post by:
Hello there, I'm really stumped... I'm fetching a web page with a script and parsing it. There is a problem because the response inserts '8 1ff8' in random places. For example, I get things...
7
by: Christoph Pieper | last post by:
Hi, we've the following problem : We have an asp-application which sets the cookie on first login. The cookie will never be touched during user access. The user can work the whole day, but...
1
by: Strange Cat | last post by:
Hi everyone! I have a weird problem with FormsAuthentication. I have an app that works just fine with FormsAuthentication. The user requests the homepage, he is redirected to login page,...
1
by: dotCore | last post by:
Hi, I have VS2003.NET, XP Pro and SQL 2000. The .NET framework is 1.1 The problem I am having with the source code is that I cannot authenticate any user. The sproc returns the user name from...
3
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
1
by: hecsan07 | last post by:
I am trying to perform site login using values from a cookie, but for some weird reason the cookie is being destroyed after the browser window is closed. I checked the browser settings for the...
6
by: kelvlam | last post by:
Hello all, I'm still a bit new with JavaScript, and I hope the guru here can shed some light for me. It's regarding handling cookie and the case-sensitive nature of JavaScript itself. My...
5
by: SJ | last post by:
Hi, In my website, i have a cookie that allows the user to remain logged in for upto 90days. So I'm setting the cookie expiration time to 90 days in the future from the time the user logs in....
3
by: SevDer | last post by:
Hi All, I am recently experiencing a weird problem. I don't know what exactly is the cause of the problem but here is my scenario and symptoms. First of all here is my architecture 1. I have...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.