473,473 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

cookie trouble

I've created a quick set of test scripts, and I'm finding that cookies
don't work as I would expect(i.e. the same as they do in original ASP.
In original ASP I could set a cookie on one page, set another value to
that cookie on a second page, then read them both back on a third page,
but in .NET the second page overwrites the first.

here are my three .NET test pages:

setCookie1.aspx:
Response.Cookies["Communities"]["LoggedIn"] = "true";
Response.Cookies["Communities"]["member_id"] = "120";
Response.Cookies["Communities"].Expires = DateTime.Now.AddYears(30);

setCookie2.aspx:
Response.Cookies["Communities"]["banner"] = "1";
Response.Cookies["Communities"].Expires = DateTime.Now.AddYears(30);

viewCookies.aspx:
System.Text.StringBuilder output = new System.Text.StringBuilder();
HttpCookie aCookie;
for(int i=0; i<Request.Cookies.Count; i++)
{
aCookie = Request.Cookies[i];
output.Append("Cookie name = " + Server.HtmlEncode(aCookie.Name) +
"<br />");
output.Append("Cookie value = " + Server.HtmlEncode(aCookie.Value)
+ "<br /><br />");
}
Response.Write(output.ToString());
am I doing something wrong? In the real world here what I need to do:

I have a template that reads from the "Communities" cookie for the
value of the "LoggedIn" name, and if it's "true" does some database
work using the value of "member_id".

Later in this template I look for the value of "banner" and display a
graphic based on that value. I then increment the value and write it
back to the cookie.

It's at this point that "LoggedIn" and "member_id" are removed from the
cookie, and "banner" is added in their place. What I really would like
is for "banner" to be appended to the "Communities" cookie, and for all
three name-value pairs to be available, as I can do is original ASP.

Any ideas?

Jul 20 '06 #1
3 1310
That's because you are not using them correctly. Use HTTPCookie everywhere.
Don't use Response & Request.Cookie.
"Kevin Blount" <ke**********@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
I've created a quick set of test scripts, and I'm finding that cookies
don't work as I would expect(i.e. the same as they do in original ASP.
In original ASP I could set a cookie on one page, set another value to
that cookie on a second page, then read them both back on a third page,
but in .NET the second page overwrites the first.

here are my three .NET test pages:

setCookie1.aspx:
Response.Cookies["Communities"]["LoggedIn"] = "true";
Response.Cookies["Communities"]["member_id"] = "120";
Response.Cookies["Communities"].Expires = DateTime.Now.AddYears(30);

setCookie2.aspx:
Response.Cookies["Communities"]["banner"] = "1";
Response.Cookies["Communities"].Expires = DateTime.Now.AddYears(30);

viewCookies.aspx:
System.Text.StringBuilder output = new System.Text.StringBuilder();
HttpCookie aCookie;
for(int i=0; i<Request.Cookies.Count; i++)
{
aCookie = Request.Cookies[i];
output.Append("Cookie name = " + Server.HtmlEncode(aCookie.Name) +
"<br />");
output.Append("Cookie value = " + Server.HtmlEncode(aCookie.Value)
+ "<br /><br />");
}
Response.Write(output.ToString());
am I doing something wrong? In the real world here what I need to do:

I have a template that reads from the "Communities" cookie for the
value of the "LoggedIn" name, and if it's "true" does some database
work using the value of "member_id".

Later in this template I look for the value of "banner" and display a
graphic based on that value. I then increment the value and write it
back to the cookie.

It's at this point that "LoggedIn" and "member_id" are removed from the
cookie, and "banner" is added in their place. What I really would like
is for "banner" to be appended to the "Communities" cookie, and for all
three name-value pairs to be available, as I can do is original ASP.

Any ideas?

Jul 20 '06 #2
Arh.. thanks for the heads up. I'm new at this and figured Microsoft's
website knew what it was talking about hehe

I'll check out HTTPCookie and see what gives.

Many thanks

Kevin

Scott M. wrote:
That's because you are not using them correctly. Use HTTPCookie everywhere.
Don't use Response & Request.Cookie
Jul 20 '06 #3
I did the research, but I still cannot get a working test.

The research does show that Response.Cookie.Add is the proper code, but
if I use this on two pages, the second pages overwrite the cookie
written on the first.

Again, I want pag 1 to set a "Communities" cookie with "loggedin=true"
and "member_id=120", and page2 to append to that "Communities" cookie
"banner=1", then for page 3 to read the cookie collection "Communities"
and show a value of "loggedin=true&member_id=120&banner=1"

Doesn't anyone know how? Sample code or URLs would be greatly
apprecaited.

Kevin
Scott M. wrote:
That's because you are not using them correctly. Use HTTPCookie everywhere.
Don't use Response & Request.Cookie
Jul 20 '06 #4

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

Similar topics

6
by: Alexandre | last post by:
What's the best I can do to solve my trouble : I got a simple page index-tmp who include a code snippet who test if a cookie exist and if yes redirect to the user account page but the trouble is...
6
by: Denna | last post by:
Hello, I'm having a little trouble with cookies, I can write one when I press a button using the following code:- HttpCookie myCookie = new HttpCookie("MyTestCookie"); myCookie.Value =...
0
by: Kepler | last post by:
I'm testing very basic FormsAuthentication and having trouble with non-persistent cookies. Once authenticated with a non-persistent cookie, if I leave the browser alone for 30 minutes,...
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...
2
by: Owen | last post by:
I have a web app that is a mixture of ASP and ASP.NET pages. Largely the only data passed between them is via the querystring, or by reading from a database. However there is a requirement for...
1
by: ticmanis | last post by:
Hello, I'm having trouble getting MSIE 6.0 (running on XP SP2) to accept a cookie which works fine in both Firefox and wget. The web server is Boa 0.94.13 (a small embedded server) using PHP...
1
by: BJörn Lindqvist | last post by:
Hello, I have some very serious trouble getting cookes to work. After a lot of work (urllib2 is severly underdocumented, arcane and overengineerd btw) I'm finally able to accept cookes from a...
3
by: Groove | last post by:
Hey guys - hoping you can help me out here. I'm using asp.net 2 (VB) and trying to set and retrieve values from a cookie. I've done this a few times before w/o a problem but I seem to be...
3
by: lawrence k | last post by:
This site was working: http://www.thesecondroad.org/ Now I'm told people are unable to create new accounts or log in. One theory: It seems that cookies are not being set. Our beta testers...
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
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...
0
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,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.