Home All Groups Group Topic Archive Search About

remember me cookie in asp .net

Author
7 Jan 2006 2:15 PM
James
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!!!

Author
7 Jan 2006 11:06 PM
Elton W
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


Show quoteHide quote
"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!!!
>
>
>
Are all your drivers up to date? click for free checkup

Author
8 Jan 2006 1:57 AM
Peter Bromberg [C# MVP]
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




Show quoteHide quote
"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!!!
>
>
>
Author
8 Jan 2006 2:10 AM
clintonG
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/


Show quoteHide quote
"James" <poop***@gmail.com> wrote in message
news:OgDVlT5EGHA.1028@TK2MSFTNGP11.phx.gbl...
> 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!!!
>
>
Author
8 Jan 2006 4:21 AM
James
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!
Author
8 Jan 2006 6:31 PM
Jon Paal
hi poopy,

this may help

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



Show quoteHide quote
"James" <poop***@gmail.com> wrote in message news:%23V2AOsAFGHA.1312@TK2MSFTNGP09.phx.gbl...
> 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!
>

Bookmark and Share