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.
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.
|