Remember Me
-
Hi all, Im using a login control in my application.In that the Remember me check box is not working fine.when i close the app. and open in a new tab the session maintains. But when i close the browser and open in a new browser i cant able to open the application.Solve my problem please. code behind:
void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{
string username = Login1.UserName.Trim();
if (!string.IsNullOrEmpty(username))
{
MembershipUser user = Membership.GetUser(username);
if (user != null)
{
// Only adjust the UserName if the password is correct. This is more secure
// so a hacker can't find valid usernames if we adjust the case of mis-cased
// usernames with incorrect passwords.if (Membership.ValidateUser(user.UserName, Login1.Password)) { Login1.UserName = user.UserName; CheckBox Remember = (CheckBox)Login1.FindControl("RememberMe"); if (Remember.Checked == true) { Response.Cookies\["UserName"\].Value = Login1.UserName; Response.Cookies\["UserName"\].Expires = DateTime.Now.AddDays(7); Response.Cookies\["Password"\].Value = Login1.Password; Response.Cookies\["Password"\].Expires = DateTime.Now.AddDays(7); } else { Response.Cookies\["UserName"\].Expires = DateTime.Now.AddDays(-7); Response.Cookies\["Password"\].Expires = DateTime.Now.AddDays(-7); }
......
Web config:
<authentication mode="Forms">
<forms timeout="30" protection="All"
slidingExpiration="true" loginUrl="http://localhost/OliveTreeNetwork/login.aspx" cookieless="UseCookies"/>
</authentication> -
Hi all, Im using a login control in my application.In that the Remember me check box is not working fine.when i close the app. and open in a new tab the session maintains. But when i close the browser and open in a new browser i cant able to open the application.Solve my problem please. code behind:
void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{
string username = Login1.UserName.Trim();
if (!string.IsNullOrEmpty(username))
{
MembershipUser user = Membership.GetUser(username);
if (user != null)
{
// Only adjust the UserName if the password is correct. This is more secure
// so a hacker can't find valid usernames if we adjust the case of mis-cased
// usernames with incorrect passwords.if (Membership.ValidateUser(user.UserName, Login1.Password)) { Login1.UserName = user.UserName; CheckBox Remember = (CheckBox)Login1.FindControl("RememberMe"); if (Remember.Checked == true) { Response.Cookies\["UserName"\].Value = Login1.UserName; Response.Cookies\["UserName"\].Expires = DateTime.Now.AddDays(7); Response.Cookies\["Password"\].Value = Login1.Password; Response.Cookies\["Password"\].Expires = DateTime.Now.AddDays(7); } else { Response.Cookies\["UserName"\].Expires = DateTime.Now.AddDays(-7); Response.Cookies\["Password"\].Expires = DateTime.Now.AddDays(-7); }
......
Web config:
<authentication mode="Forms">
<forms timeout="30" protection="All"
slidingExpiration="true" loginUrl="http://localhost/OliveTreeNetwork/login.aspx" cookieless="UseCookies"/>
</authentication>For version 2.0 the ASP.NET team changed the timeout for persistent cookies to use the
<forms timeout=""/>
attribute. So the life of the persistent cookie then matches the lifetime of session based cookies. In your example, the cookie will last 30 minutes. -
For version 2.0 the ASP.NET team changed the timeout for persistent cookies to use the
<forms timeout=""/>
attribute. So the life of the persistent cookie then matches the lifetime of session based cookies. In your example, the cookie will last 30 minutes.