Click here to Skip to main content
16,018,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
i want the user to be remain logged in even after the browser will be closed
how can i do that
uptill now what i have done is
System.Web.Security.FormsAuthentication.SetAuthCookie(userName, true);
but unfortunatelly when the browser is closed the user will be loged out...
that i dont want to do
help me plz
Posted
Comments
haseebsvirgo 22-Mar-11 16:12pm    
if any one could solve my prob...

This is a not the correct way to do it. SetAuthCookie is only valid for the current browser session. Most browsers have functionality to allow the user to "remember" credentials, and those credentials are kept in encrypted form on the user's machine. Let them use the browser to do this.

You could try using google. I searched for "asp.net remember me functionality", and got back more than 2.4 million results back:

http://forums.asp.net/t/1087450.aspx/1?ASP+Login+Remember+Me+functionality[^]
 
Share this answer
 
Comments
haseebsvirgo 22-Mar-11 15:49pm    
if thats not the accurate method then what can i do except this to keep the user remain looged in ....
haseebsvirgo 22-Mar-11 15:53pm    
private void ValidateLogin(string emailAddress, string password)
{
try
{
UserInfo objUserInfo = null;
objUserInfo = Gateway.Users.ValidateLogin(emailAddress, password);

if (objUserInfo == null || objUserInfo.UserID == 0)
{
lblError.Text = IEC_Common.Messages.MSG_INVALID_USERNAME_PWD;
trErrorMsg.Visible = true;
return;
}

//if (!IEC_Data_Access.DatabaseUtility.ValidateLogin(emailAddress, password, ref objUserInfo))
//{
// lblError.Text = IEC_Common.Messages.MSG_INVALID_USERNAME_PWD;
// trErrorMsg.Visible = true;
// return;
//}

LoginManager.LogInUser(objUserInfo);

// Create the cookie that contains the forms authentication ticket

HttpCookie authCookie = FormsAuthentication.GetAuthCookie(emailAddress, true);

// Get the FormsAuthenticationTicket out of the encrypted cookie

FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);

// Create a new FormsAuthenticationTicket that includes our custom User Data

FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, "");

// Update the authCookie's Value to use the encrypted version of newTicket

authCookie.Value = FormsAuthentication.Encrypt(newTicket);

// Manually add the authCookie to the Cookies collection

Response.Cookies.Add(authCookie);

// Determine redirect URL and send user there

string redirUrl = FormsAuthentication.GetRedirectUrl(emailAddress, chkLogin.Checked);

//if (!redirUrl.Contains("MENU_ID="))
//{
// redirUrl += "?MENU_ID=35";
//}

Response.Redirect(Navigation.GetTamperProofURL(redirUrl));

}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
}


this is my code
"asp.net remember me functionality" will just remember the password but it's not give you, what u searching for.
Just try folllwing steps

1. Put your Username and password in Cookies

2. on LOAD of login page just check your cookies has username and password stored for that machin, If yes the directly redirect to Menu page not login page.

3. if user press LOGOUT button destroy that cookies.
 
Share this answer
 
You can achieve this my setting a persistent cookie. Mind you though, if you go this path, the user will remain "logged" ( means, even though their session is timed out, you application will be able to recognize them, next time they come around)

unfortunately, persist cookie behavior is removed from System.Web.Security.FormsAuthentication. But don't loose a sleep there is a way to achieve what you want. Let this be your guide. http://geekswithblogs.net/vivek/archive/2006/10/13/93956.aspx[^]
 
Share this answer
 
Comments
haseebsvirgo 22-Mar-11 16:08pm    
problem still continues....
Yusuf 22-Mar-11 22:14pm    
That is not helpful comment. What does that mean? How can that help clarify your situation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900