Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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 April 7th, 2004, 01:33 PM
Registered User
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help: Cookies not getting set (c#)

Hi all,

I am trying to create cookies on the login page and then redirect the user to the next page using Response.Redirect. But I am unable to read Request.Cookies on the next page. Only the "ASP.NET_SessionID" cookie is getting saved.

I do not understand what the problem might be. I checked the webconfig file to confirm that the cookies are enabled.

I am using the following code for saving the cookie:

HttpCookie MyCookie = new HttpCookie("Background");
MyCookie.Value = "blue";
DateTime dt = DateTime.Now;
TimeSpan ts = new TimeSpan(1,30,0,0,0);
MyCookie.Expires = dt + ts;
Response.Cookies.Add(MyCookie);

AND the following code for reading it:
HttpCookie cookie = Request.Cookies["Background"];
if (cookie != null)
{
    string b= cookie.Value.ToString();
    Response.Write("Background is :"+ b);
}
else
{
    Response.Write("Cookie not found. <br>");
}


Please help me debug this.

Thanks in advance,
Meetali.

 
Old April 8th, 2004, 12:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

excuse me but I wonder why do u wanna read that cookie?!

Always:),
Hovik Melkomian.
 
Old April 8th, 2004, 01:44 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 Meetali,

The code you posted should work fine. Are you sure that your system allows cookies to be set? E.g. did you block cookies in Internet Explorer, or does your firewall block them all?

I copied and pasted your code to a test page and it worked fine. Did you put the code at the right locations (for example, in Page_Load?)

Hovik: I would almost say: Why wouldn't you want to read the cookie? It's common practice to set a cookie at one page, and retrieve it again on another page. Isn't that what cookies are for??

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old April 8th, 2004, 07:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

NO my dear friend Imar: Yes! u r right but I didnt meant that!
I didnt know how is he going to validate user so I guess he is using ASP.net AUTHENTICATION! So i that case he didnt need to read the cookies diractly & ... does he?!
in other case cookie can not be a good was to contol user authentication isnt it?!

sorry for my bad response.

Always:),
Hovik Melkomian.
 
Old April 8th, 2004, 08:01 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

??? What do these cookies have to do with authentication? In the original post, nothing seems to relate to authentication. Or am I missing something?



---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old April 8th, 2004, 01:13 PM
Registered User
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar. It seems that the firewall was blocking the cookies.
Thanks again.

--Meetali.








Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath: set operation with a disjoint node set rich_unger XSLT 7 May 6th, 2008 09:24 AM
how Set Multiple values in cookies amol_0008 JSP Basics 1 May 31st, 2007 06:27 AM
Help: Cookies not getting set (c#) meetali ASP.NET 1.0 and 1.1 Basics 0 April 7th, 2004 02:52 PM
Can't set cookies meckeard ASP.NET 1.0 and 1.1 Basics 7 September 8th, 2003 12:41 PM





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