Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > remember me cookie in asp .net

Reply
Thread Tools

remember me cookie in asp .net

 
 
James
Guest
Posts: n/a
 
      01-07-2006
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")("use rId"))

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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?RWx0b24gVw==?=
Guest
Posts: n/a
 
      01-07-2006
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")("use rId"))
>
> 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!!!
>
>
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      01-08-2006
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")("use rId"))
>
> 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!!!
>
>
>

 
Reply With Quote
 
clintonG
Guest
Posts: n/a
 
      01-08-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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")("use rId"))
>
> 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!!!
>
>



 
Reply With Quote
 
James
Guest
Posts: n/a
 
      01-08-2006
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!


 
Reply With Quote
 
Jon Paal
Guest
Posts: n/a
 
      01-08-2006
hi poopy,

this may help

http://msdn2.microsoft.com/en-us/lib...et.cookie.aspx



"James" <(E-Mail Removed)> wrote in message news:%(E-Mail Removed)...
> 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!
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LoginCtl Remember Me Checkbox -> How to keep it checked and remember user? Frank Miverk ASP .Net 0 04-18-2007 08:13 PM
Convert a PHP cookie to an ASP.NET cookie =?Utf-8?B?TnVubw==?= ASP .Net 1 01-31-2006 03:08 PM
Any downsides to cookie assignment inside custom class using HttpContext.Current? ASP.NET 2.0 cookie fix? ASP .Net 2 08-17-2005 06:43 AM
Cookie and Session Cookie Questions. Shapper ASP .Net 1 04-27-2005 11:20 AM
Session cookie? Browser instance cookie? Ben ASP .Net 3 06-03-2004 03:41 AM



Advertisments