Remember Me on this Machine

S

Samuel Shulman

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

Thank you,
Samuel
 
J

John Timney \( MVP \)

If all your looking to do is set a cookie and retrive it then its as easy
as:

Using System.Web;
Response.Cookies["username"].Value = "Fred";

and to read it back again
Response.Write(Request.Cookies["username"].Value);

There are some examples around already using forms authentication like
http://www.aspcode.net/default.aspx?p=a&i=112

I'm sure you can fish around for more.

--
Regards

John Timney
Microsoft MVP
 
S

Samuel Shulman

Thank you for your response,

It doesn't seem to work on my machine

Does the following line:
Response.Cookies["username"].Value = "Fred";
suppose to save the cookie in file so it can be used in the Load event of
the Login page next time the user will try to log on

Samuel

John Timney ( MVP ) said:
If all your looking to do is set a cookie and retrive it then its as easy
as:

Using System.Web;
Response.Cookies["username"].Value = "Fred";

and to read it back again
Response.Write(Request.Cookies["username"].Value);

There are some examples around already using forms authentication like
http://www.aspcode.net/default.aspx?p=a&i=112

I'm sure you can fish around for more.

--
Regards

John Timney
Microsoft MVP


--
Regards

John Timney
Microsoft MVP

Samuel Shulman said:
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

Thank you,
Samuel
 
J

John Timney \( MVP \)

I forgot to give you the line for cookie duration

Response.Cookies["username"].Value = "Fred"
Response.Cookies["username"].Expires = DateTime.Now.AddDays(1)

That way when you try and read it back it should exist in the clients
browser cookie cache.

Have a read of the cookie guide for asp.net - it explains it all
beautifully.
http://msdn.microsoft.com/library/d...s/dv_vstechart/html/vbtchASPNETCookies101.asp

--
Regards

John Timney
Microsoft MVP

Samuel Shulman said:
Thank you for your response,

It doesn't seem to work on my machine

Does the following line:
Response.Cookies["username"].Value = "Fred";
suppose to save the cookie in file so it can be used in the Load event of
the Login page next time the user will try to log on

Samuel

John Timney ( MVP ) said:
If all your looking to do is set a cookie and retrive it then its as easy
as:

Using System.Web;
Response.Cookies["username"].Value = "Fred";

and to read it back again
Response.Write(Request.Cookies["username"].Value);

There are some examples around already using forms authentication like
http://www.aspcode.net/default.aspx?p=a&i=112

I'm sure you can fish around for more.

--
Regards

John Timney
Microsoft MVP


--
Regards

John Timney
Microsoft MVP

Samuel Shulman said:
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

Thank you,
Samuel
 
S

Samuel Shulman

I managed to write but I can't read,
Is it related to the fact that it is running on my own computer?
Is it because it is the first request?
The code is below

Thank you,
Samuel
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

obLogin = New clsLoginManager(Session)

'Read the username from the machine

If Not IsNothing(Response.Cookies("Username")) Then

If Not IsNothing(Response.Cookies("Username").Value) Then

txtUserName.Text = Response.Cookies("Username").Value.ToString

End If

End If



End Sub


John Timney ( MVP ) said:
I forgot to give you the line for cookie duration

Response.Cookies["username"].Value = "Fred"
Response.Cookies["username"].Expires = DateTime.Now.AddDays(1)

That way when you try and read it back it should exist in the clients
browser cookie cache.

Have a read of the cookie guide for asp.net - it explains it all
beautifully.
http://msdn.microsoft.com/library/d...s/dv_vstechart/html/vbtchASPNETCookies101.asp

--
Regards

John Timney
Microsoft MVP

Samuel Shulman said:
Thank you for your response,

It doesn't seem to work on my machine

Does the following line:
Response.Cookies["username"].Value = "Fred";
suppose to save the cookie in file so it can be used in the Load event of
the Login page next time the user will try to log on

Samuel

John Timney ( MVP ) said:
If all your looking to do is set a cookie and retrive it then its as
easy as:

Using System.Web;
Response.Cookies["username"].Value = "Fred";

and to read it back again
Response.Write(Request.Cookies["username"].Value);

There are some examples around already using forms authentication like
http://www.aspcode.net/default.aspx?p=a&i=112

I'm sure you can fish around for more.

--
Regards

John Timney
Microsoft MVP


--
Regards

John Timney
Microsoft MVP

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

Thank you,
Samuel
 

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

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top