remember me cookie in asp .net

Discussion in 'ASP .Net' started by James, Jan 7, 2006.

  1. James

    James Guest

    hi,
    I'm trying to remember a user who has visited the page. what i found out was
    to use persistent cookie, is there any other way that i can remember the
    user next time he visit?

    When using cookies, I used the code below to add
    -----in login.aspx------
    Dim aCookie As New HttpCookie("userInfo")
    aCookie.Values("userID") = "1"
    aCookie.Expires = DateTime.Now.AddYears(50)
    Response.Cookies.Add(aCookie)

    and to retrieve, I used
    -----in default.aspx------
    Server.HtmlEncode(Request.Cookies("userInfo")("userId"))

    but I wasn't able to retrieve values from the cookies. does it matter where
    I create the cookies, as i check for the cookie in default.aspx and redirect
    to login.aspx if the cookie is not found.

    Hope someone can help!

    Thank You!!!
     
    James, Jan 7, 2006
    #1
    1. Advertising

  2. Hi James,

    One possible reason you can't retrieve cookie is that your browser blocks
    cookie. Hence it never writes cookie to client computer.

    HTH

    Elton Wang


    "James" wrote:

    > hi,
    > I'm trying to remember a user who has visited the page. what i found out was
    > to use persistent cookie, is there any other way that i can remember the
    > user next time he visit?
    >
    > When using cookies, I used the code below to add
    > -----in login.aspx------
    > Dim aCookie As New HttpCookie("userInfo")
    > aCookie.Values("userID") = "1"
    > aCookie.Expires = DateTime.Now.AddYears(50)
    > Response.Cookies.Add(aCookie)
    >
    > and to retrieve, I used
    > -----in default.aspx------
    > Server.HtmlEncode(Request.Cookies("userInfo")("userId"))
    >
    > but I wasn't able to retrieve values from the cookies. does it matter where
    > I create the cookies, as i check for the cookie in default.aspx and redirect
    > to login.aspx if the cookie is not found.
    >
    > Hope someone can help!
    >
    > Thank You!!!
    >
    >
    >
     
    =?Utf-8?B?RWx0b24gVw==?=, Jan 7, 2006
    #2
    1. Advertising

  3. James,
    Here is some very simple cookie code as an example:

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(Request.Cookies["test"]==null)
    {
    HttpCookie c = new HttpCookie("test","hello") ;
    c.Expires=new DateTime(2007,1,1);
    Response.Cookies.Add(c);
    }
    Response.Write(Request.Cookies["test"].Value);
    //....

    Peter
    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "James" wrote:

    > hi,
    > I'm trying to remember a user who has visited the page. what i found out was
    > to use persistent cookie, is there any other way that i can remember the
    > user next time he visit?
    >
    > When using cookies, I used the code below to add
    > -----in login.aspx------
    > Dim aCookie As New HttpCookie("userInfo")
    > aCookie.Values("userID") = "1"
    > aCookie.Expires = DateTime.Now.AddYears(50)
    > Response.Cookies.Add(aCookie)
    >
    > and to retrieve, I used
    > -----in default.aspx------
    > Server.HtmlEncode(Request.Cookies("userInfo")("userId"))
    >
    > but I wasn't able to retrieve values from the cookies. does it matter where
    > I create the cookies, as i check for the cookie in default.aspx and redirect
    > to login.aspx if the cookie is not found.
    >
    > Hope someone can help!
    >
    > Thank You!!!
    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jan 8, 2006
    #3
  4. James

    clintonG Guest

    IE Cookie Viewer is a good tool to find and use when debugging cookies. So
    is any recent releases of Firefox or Netscape.


    <%= Clinton Gallagher
    METROmilwaukee (sm) "A Regional Information Service"
    NET csgallagher AT metromilwaukee.com
    URL http://metromilwaukee.com/
    URL http://clintongallagher.metromilwaukee.com/


    "James" <> wrote in message
    news:...
    > hi,
    > I'm trying to remember a user who has visited the page. what i found out
    > was
    > to use persistent cookie, is there any other way that i can remember the
    > user next time he visit?
    >
    > When using cookies, I used the code below to add
    > -----in login.aspx------
    > Dim aCookie As New HttpCookie("userInfo")
    > aCookie.Values("userID") = "1"
    > aCookie.Expires = DateTime.Now.AddYears(50)
    > Response.Cookies.Add(aCookie)
    >
    > and to retrieve, I used
    > -----in default.aspx------
    > Server.HtmlEncode(Request.Cookies("userInfo")("userId"))
    >
    > but I wasn't able to retrieve values from the cookies. does it matter
    > where
    > I create the cookies, as i check for the cookie in default.aspx and
    > redirect
    > to login.aspx if the cookie is not found.
    >
    > Hope someone can help!
    >
    > Thank You!!!
    >
    >
     
    clintonG, Jan 8, 2006
    #4
  5. James

    James Guest

    Hi,

    Thanks for your replies!
    I did a check, had my browser to allowed cookies, the cookie was created
    thou, but using IE Cookie Viewer recommended by Clinton, the value UserID =
    1 was stored when I first access my page, but when I access it the second
    time, the cookie exists but the value disappeared!

    Is there other possibilities, or any mistake that I could have made?

    Thank you! Hope to hear from you soon!
     
    James, Jan 8, 2006
    #5
  6. James

    Jon Paal Guest

    hi poopy,

    this may help

    http://msdn2.microsoft.com/en-us/library/system.net.cookie.aspx



    "James" <> wrote in message news:%...
    > Hi,
    >
    > Thanks for your replies!
    > I did a check, had my browser to allowed cookies, the cookie was created thou, but using IE Cookie Viewer recommended by Clinton,
    > the value UserID = 1 was stored when I first access my page, but when I access it the second time, the cookie exists but the value
    > disappeared!
    >
    > Is there other possibilities, or any mistake that I could have made?
    >
    > Thank you! Hope to hear from you soon!
    >
     
    Jon Paal, Jan 8, 2006
    #6
    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. gencode
    Replies:
    4
    Views:
    10,004
    gencode
    Nov 8, 2005
  2. =?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:
    452
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jan 31, 2006
  3. Rob R. Ainscough
    Replies:
    3
    Views:
    5,031
    tdavisjr
    Mar 22, 2006
  4. Frank Miverk
    Replies:
    0
    Views:
    686
    Frank Miverk
    Apr 18, 2007
  5. Abdo Haji-Ali

    ASP.NET "Remember Me" check box

    Abdo Haji-Ali, Aug 27, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    796
    Abdo Haji-Ali
    Aug 27, 2007
Loading...

Share This Page