I have so many developers asking me this question that I decided to write a post about it.
Here's what happens:
1) Lets say I add a ASP.NET Login control to a page called "Login.aspx"
2) I set the DestinationPageUrl property to "Success.aspx"
3) I use the ASP.NET configuration tool to create users
4) I run the webapp and access Login.aspx from my browser. I give the proper username and password, I also check the "Remember me next time" checkbox and click login. It takes me to Success.aspx.
So far so good.
5) Now if I close my browser and open a new instance (or i run the application again) and access Login.aspx, you'd expect it not to ask username/password again and directly take you to Success.aspx, cos we've already done a "remember me".
It doesnt seem to work as expected. If you look up the Cookies folder on the machine, a cookie has been created. But it still doesn't seem to work.
Well, just add these few lines to Page_Load of Login.aspx to make it work:
The cookie is actually working, that's why the next time you access any page on the site, the User.Identity will reflect the user that was saved with "Remember me.." option. We just have to check for User.Identity.IsAuthenticated in login page and redirect
on to our DestinationPageUrl if it's true.
I hope this helps.
- &
login controlRemember me next time not workingRemember me problemASP .NET 2.0 Membership
I'm having this problem, too. I've tried everything I've seen on forums, but still no luck. I'm trying to get it so that if you log out, it will remember the username and password and if you checked the remember me box or not.
I have the same problem too, i can fix it in this way
<asp:Login
EnableViewState="true"
The property "remember me" was correctly setted from cookies, but the login page do a postback and it's value where lost, setting EnableViewState to true the login control preserves it's properties.
i hope this could help and sorry for my english.
After banging my head on the wall like everyone else for quite a bit, I finally found a solution that's working for me. It's rather simple too. The missing pieces are the "name" and "path" properties in the authentication/forms node of web.config.
Here's what I added to mine to make it work:
<authentication
mode="Forms">
<
forms
name="yourAppName"
path="/"
timeout="500000"
slidingExpiration="true"/>
</
authentication>
Without these properties, the authentication would always timeout in 30 minutes (without revisiting the site). I guess these properties in the cookie are crucial for this to work. I just used my domain name for the "name" property and it's working perfectly.
I would assume any unique name should work, although I didn't try anything different.
To keep the maintenance to a minimum and not require compiling, remember to use the defaultUrl property in the response.redirect when the user is authenticated during the page_load. Use the following in your login page Page_Load event:
Most people are confused because they think the login workflow uses the same cookies with the session management workflow. In fact, they are 2 different checks using 2 different cookies. Full explanation: http://www.codeproject.com/Tips/779844/Remember-Me
login controlRemember me next time not workingRemember me problemASP .NET 2.0 Membership
None
0 Points
2 Posts
"Remember me next time" not working for Login control? Here's why!
May 10, 2008 10:35 AM|anandgothe|LINK
I have so many developers asking me this question that I decided to write a post about it.
Here's what happens:
1) Lets say I add a ASP.NET Login control to a page called "Login.aspx"
2) I set the DestinationPageUrl property to "Success.aspx"
3) I use the ASP.NET configuration tool to create users
4) I run the webapp and access Login.aspx from my browser. I give the proper username and password, I also check the "Remember me next time" checkbox and click login. It takes me to Success.aspx.
So far so good.
5) Now if I close my browser and open a new instance (or i run the application again) and access Login.aspx, you'd expect it not to ask username/password again and directly take you to Success.aspx, cos we've already done a "remember me".
It doesnt seem to work as expected. If you look up the Cookies folder on the machine, a cookie has been created. But it still doesn't seem to work.
Well, just add these few lines to Page_Load of Login.aspx to make it work:
protected void Page_Load(object sender, EventArgs e){
if (User.Identity.IsAuthenticated == true)
{
Response.Redirect("Success.aspx");
}
}
The cookie is actually working, that's why the next time you access any page on the site, the User.Identity will reflect the user that was saved with "Remember me.." option. We just have to check for User.Identity.IsAuthenticated in login page and redirect on to our DestinationPageUrl if it's true.
I hope this helps.
- &
login control Remember me next time not working Remember me problem ASP .NET 2.0 Membership
Contributor
5578 Points
3325 Posts
MVP
Re: "Remember me next time" not working for Login control? Here's why!
May 10, 2008 11:25 AM|albertpascual|LINK
You need to set the cookie or use Forms authentication to generate the cookie to stay for more than the session.
Al
My Blog
None
0 Points
2 Posts
Re: "Remember me next time" not working for Login control? Here's why!
May 15, 2008 05:55 AM|anandgothe|LINK
Member
12 Points
49 Posts
Re: "Remember me next time" not working for Login control? Here's why!
Nov 10, 2008 09:38 AM|relish27|LINK
I'm having this problem, too. I've tried everything I've seen on forums, but still no luck. I'm trying to get it so that if you log out, it will remember the username and password and if you checked the remember me box or not.
Form:
<asp:Login ID="Login1" runat="server" RememberMeSet="true" CssClass="loginClass" TitleText="">
</asp:Login>
In the web.config:
<forms name=".ASPXFORMSAUTH" protection="All" defaultUrl="/admin/default.aspx" loginUrl="/login.aspx" cookieless="UseCookies" timeout="600000" slidingExpiration="true">
And I also added a machineKey. What else am I missing? I would have thought that it would remember the username and password automatically.
Member
10 Points
113 Posts
Re: "Remember me next time" not working for Login control? Here's why!
Dec 18, 2008 05:15 PM|Dango23|LINK
I have the same problem :-(
Can any expert answer on this issue?
What really need to be done, step by step, in order for this option to work as it should? I have tried all what is written here and nothing helped.
None
0 Points
1 Post
Re: "Remember me next time" not working for Login control? Here's why!
Dec 29, 2008 01:12 PM|Dario1976|LINK
I have the same problem too, i can fix it in this way
<asp:Login EnableViewState="true"
The property "remember me" was correctly setted from cookies, but the login page do a postback and it's value where lost, setting EnableViewState to true the login control preserves it's properties.
i hope this could help and sorry for my english.
None
0 Points
1 Post
Re: "Remember me next time" not working for Login control? Here's why!
Feb 19, 2009 05:41 PM|dlhoppe|LINK
After banging my head on the wall like everyone else for quite a bit, I finally found a solution that's working for me. It's rather simple too. The missing pieces are the "name" and "path" properties in the authentication/forms node of web.config.
Here's what I added to mine to make it work:
<authentication mode="Forms"><
forms name="yourAppName" path="/" timeout="500000" slidingExpiration="true"/></
authentication>Without these properties, the authentication would always timeout in 30 minutes (without revisiting the site). I guess these properties in the cookie are crucial for this to work. I just used my domain name for the "name" property and it's working perfectly. I would assume any unique name should work, although I didn't try anything different.
I hope this helps somebody.
Member
3 Points
37 Posts
Re: "Remember me next time" not working for Login control? Here's why!
Mar 18, 2009 01:02 PM|skydiverMN|LINK
To keep the maintenance to a minimum and not require compiling, remember to use the defaultUrl property in the response.redirect when the user is authenticated during the page_load. Use the following in your login page Page_Load event:
protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated == true)
{
Response.Redirect(FormsAuthentication.DefaultUrl, true);
}
}
Now, you just need to modify the redirect location in one place, assuming you actually added the defaultUrl into the web.config forms tag!
<authentication mode="Forms">
<formS class=st loginUrl=" protection="All" defaultUrl="default.aspx" timeout="20" name=".SecurityFormsAuth" slidingExpiration="true" cookieless="UseCookies">
</formS>
defaultUrl response.redirect isAuthenticated formsauthentication
None
0 Points
2 Posts
Re: "Remember me next time" not working for Login control? Here's why!
Jun 12, 2014 09:41 AM|Believe2014|LINK
Most people are confused because they think the login workflow uses the same cookies with the session management workflow. In fact, they are 2 different checks using 2 different cookies. Full explanation: http://www.codeproject.com/Tips/779844/Remember-Me
login control Remember me next time not working Remember me problem ASP .NET 2.0 Membership