473,806 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.QuerySt ring("passedVal ").ToString
Dim aCookie As HttpCookie = Request.Cookies ("MyCookie")
aCookie.Values( "value1") = aCookie.Values( "value1") + 1
aCookie.Values( "value2") = aCookie.Values( "value2").ToStr ing & i & ";"
Response.Redire ct("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 1430
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.QuerySt ring("passedVal ").ToString
Dim aCookie As HttpCookie = Request.Cookies ("MyCookie")
aCookie.Values( "value1") = aCookie.Values( "value1") + 1
aCookie.Values( "value2") = aCookie.Values( "value2").ToStr ing & i & ";"
Response.Redire ct("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.Cookie s.

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
4625
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 like 8< tr1ff8> or
7
2148
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 after 6 to 7 hours, the cookie get 2-4 new asp-sessionid's thus overwriting the very first entries in the cookie. Does anyone had the same problem or has a solution. The server is a w2003 enterprise the client has windows xp sp2.
1
1554
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, then enters valid username and password that are checked versus a db table, if the info is ok i execute SetAuthCookie(xxx, False) then i open a new window which displays the home page, all is working fine...
1
1146
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 database which also means that the user should be authenticated. It runs the SetAuthCookie method with success. The resulting page is no different than the initial page. The login component is still there. When I try to access an admin page directly...
3
11130
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 behind and don't use a domain then I can not change or remove that cookie's value on the client. If I subsequently create the cookie again in the codebehind then I actually end up with TWO cookies with the same name in the response. The cookie...
1
1701
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 cookies, and there is nothing there that terminates cookies uopn browser close. The following is a sample of the code I am runinng: To write the cookie: This code runs if the user is not logged on the site and the cookie does not exist.
6
2704
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 problem is how do I handle the "path" parameter in cookie. First, the sequence start at http://www.testServer1.com/TestApp/page1.htm, and a cookie is set at
5
2229
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. I've been testing my code and for some reason, the cookie expires randomly before even 24 hrs has passed. Yesterday it expired after 11hrs and 20mins. Any idea why my cookie expiration isn't working?
3
3625
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 a main framework (DNN) build in VB.NET which I try to prevent changing things there (simply not changing it) 2. I have a virtual directory under this which I develop in C#.
0
9599
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10624
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10371
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10111
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5684
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3853
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.