473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

remember me cookie in asp .net

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!!!
Jan 7 '06 #1
5 4725
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!!!

Jan 7 '06 #2
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!!!

Jan 8 '06 #3
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" <po*****@gmail.com> wrote in message
news:Og**************@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")("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!!!

Jan 8 '06 #4
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!
Jan 8 '06 #5
hi poopy,

this may help

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

"James" <po*****@gmail.com> wrote in message news:%2****************@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!

Jan 8 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Joshua Beall | last post by:
Hi All, What is the best way to use a cookie to remember a logged in user? Would you store the username and password in two separate cookies? Should the password be plain text? Hashed? Not...
13
by: Kai Grossjohann | last post by:
I have a web app which comprises different frames: a menu bar frame, a search form frame, a result list frame. Depending on the state, only a subset of these frames is available. (Eg, after...
3
by: TCORDON | last post by:
Can someone give me a sample or point me in the direction of one, on how to implement User "Remember Me" option when logging into a website? TIA
1
by: | last post by:
I'm currently at the Macromedia Max Developer Conference in California and was impressed by vendor's InterAct User Authentication system which bascially allows one to smash together a 'Remember Me'...
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
3
by: Brian Henry | last post by:
I want to make a login form, but have a checkbox with a "remember user name" option to create a cookie on their system to save their user name and place it into the username text box when they...
4
by: pek | last post by:
Any ideas on how to create a remember me option in a login box..?
4
by: Samuel Shulman | last post by:
Hi How can I implement a feature of 'Remember me on this computer' I believe using cookies that next time when the user comes to the login page I can add the Userename to the appropriate Textbox...
1
by: =?Utf-8?B?QW1pciBUb2hpZGk=?= | last post by:
Hello The site I am working on redirects the user to a "session timed out" page when: - the user's session has expired AND - the user action results in a postback to the server I then...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.