让我保持登录状态,直到我注销? [英] keep me signed in until i logout?

查看:51
本文介绍了让我保持登录状态,直到我注销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我的问题是,当用户关闭浏览器时,会话将结束,并且用户将自动注销...
我使用persistantcookie=true并增加了配置文件中的超时,但是当我关闭浏览器时,仍然注销​​了用户
我希望他即使在浏览器死机后也可以登录...
我该怎么做
请帮助我....

这是我的代码

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;
            }
        }

推荐答案

尝试此链接

http://www.beansoftware.com/ASP.NET-Tutorials/Keep-Session- Alive.aspx [ ^ ]
try this link

http://www.beansoftware.com/ASP.NET-Tutorials/Keep-Session-Alive.aspx[^]


这篇关于让我保持登录状态,直到我注销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆