remember me cookie in asp .net

J

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

Guest

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
 
G

Guest

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
 
J

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

remember me cookies in asp.net 0
Remember me in Login control. 1
Weird cookie problem 2
Login Control's "Remember me" 1
cookie trouble 3
ASP NET 2.0 Cookie 8
"Remember Me" on Login form not working 6
cookie 1

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top