problem in reading cookie

  • Thread starter Thread starter jack
  • Start date Start date
J

jack

HI . i have created a cookiie in one page and i am trying to get in
other page .. but not getting to desired result.

im able to create cookie and reade it in the same page but not able to
get or read it on the redirected page ..
below is my code ..


webform1.aspx
private void Button1_Click(object sender, System.EventArgs e)
{
HttpCookie c = new HttpCookie ("mycookies","this is the content of
my cookie");
Response.Cookies.Add (c);
Response.Redirect("WebForm2.aspx");
}
webform2

private void Page_Load(object sender, System.EventArgs e)
{
Response.Write ( Response.Cookies.Count);
Response.Write ( Response.Cookies["mycookies"].Value);
}
 
Hi Jack,

To read a cookie back from a client you need to use the Request.Cookies
collection.

E.g. Response.Write ( Request.Cookies.Count);

That's it really!

Hope this helps.
 
Back
Top