problem in reading cookie

Discussion in 'ASP .Net' started by jack, Jan 10, 2006.

  1. jack

    jack Guest

    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);
    }
    jack, Jan 10, 2006
    #1
    1. Advertising

  2. jack

    Danana Guest

    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.

    jack wrote:
    > 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);
    > }
    Danana, Jan 10, 2006
    #2
    1. Advertising

  3. jack

    jack Guest

    problem solved :)
    Thanks dude..
    jack, Jan 12, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben
    Replies:
    3
    Views:
    5,830
    Steven Cheng[MSFT]
    Jun 3, 2004
  2. Shapper

    Cookie and Session Cookie Questions.

    Shapper, Apr 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    562
  3. =?Utf-8?B?UGF1bA==?=

    Cookie Question (IP as domain and cookie file location)

    =?Utf-8?B?UGF1bA==?=, Jan 10, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,471
    Bruce Barker
    Jan 10, 2006
  4. ad
    Replies:
    2
    Views:
    7,496
    Kevin Spencer
    Jan 27, 2006
  5. =?Utf-8?B?TnVubw==?=

    Convert a PHP cookie to an ASP.NET cookie

    =?Utf-8?B?TnVubw==?=, Jan 31, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    437
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jan 31, 2006
Loading...

Share This Page