Click here to Skip to main content
15,889,499 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hello
my problem is that when the user closes his/her browser the session will be ended and the user is automatically logged out...
I use persistantcookie=true and increase the timeout in my configuration file but still when i close my browser the user is logged out
i want him to be logged in even after the browser is dead...
how can i do that
plz help me....

this is my code

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;
            }
        }
Posted
Updated 23-Mar-11 2:19am
v2
Comments
Wendelius 23-Mar-11 8:19am    
pre tags added

1 solution

 
Share this answer
 

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