Xerratus
Happily stressed out, since 1974


 
Tuesday, October 31, 2006
<< If you're selling... I'm not buying
Firefox Download Manager won't let me "Save File" >>

A few weeks ago, I posted a solution I came up with a way to utilize a remember me checkbox in .NET 2.0 that, when selected, pre-populated just the username in the username textbox during subsequent visits.  The problem I found was that signing out of FormsAuthentication wiped out any and all cookies I had set during or prior to logging a user in.  So, the simple act of looking at the cookie to see if the user wanted to be remembered became quite an ordeal.  My solution was to set/get the cookie using JavaScript.  This worked and I was happy.

This is a shot of the cookie collection when the user signs out and returns to the login page:



Notice that the count of the cookie collection is 0.

There are some skeptics out there though.  So, for them, I've created a very simple website solution that tries to set and get the remember me cookie as explained above.  Now, the solution DOES NOT work.  Once a user logs out, the remember me cookie is gone, along with the saved username, and there is no way to tell if the user had selected to have his username saved. 

The challenge is to modify the solution so that it DOES work.

Post updates in the comments.  When and if a solution is found and posted in the comments, I'll add to the solution and re-post so that we can finally get around this issue.

Note: The solution is NOT using the Login control on purpose.  The goal is to have the username pre-populated but still make them login.  From my limited usage of the Login control, it appears to actually keep the user logged in.  If you can get this solution to work with the Login control, I say go for it... and more kudos to you for doing so.

The winner receives bragging rights.

Download the solution: FormsAuthenticationRememberMeChallenge.zip (5.01 KB)

(the username and password to login into the form is "test"/"1111")

UPDATE: That was fast!  Adi has come up with a winning solution.  Congrats. 

Download it here: FormsAuthenticationRememberMeSolution.zip (5.55 KB)

Tuesday, October 31, 2006 4:12:34 PM (Pacific Standard Time, UTC-08:00)
John,

Send me an email, as I don't have your's, so I can email you the source code.
Wednesday, November 01, 2006 8:29:23 AM (Pacific Standard Time, UTC-08:00)
Well done Adi!

Here is a link to your solution as-is: FormsAuthenticationRememberMeSolution.zip (5.55 KB)

As put by Adi, "It's not a challenge, just a new experience. We can always learn from each other." I couldn't agree more.

As soon as I can, I'll write a post explaining why my code didn't work and why Adi's does.
Wednesday, July 09, 2008 11:44:18 PM (Pacific Standard Time, UTC-08:00)
well, when you would like to access cookies, you should use request.cookies instead of response.cookies. response.cookies are for writing cookies and request.cookies are for writing
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview