如何在用户关闭浏览器后注销 [英] How to logout after user close browser

查看:190
本文介绍了如何在用户关闭浏览器后注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 DBConnection dbcon = new DBConnection();
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        txtUserName.Focus();
    }
    public void Trace_Session()
    {
        Session["UserNameSession"] = txtUserName.Text;
        Session["TimeLogin"] = System.DateTime.Now;

        string UserNameSession = Session["UserNameSession"].ToString();
        DateTime TimeSession =Convert.ToDateTime(Session["TimeLogin"].ToString());

        string str = dbcon.Trace_Session(UserNameSession.ToString(), TimeSession);
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string str = dbcon.Login_Verify(txtUserName.Text, txtPassword.Text);
        if (str == "valid")
        {
            Trace_Session();
            Response.Redirect("~/frmHome.aspx");
        }
        else if (str == "invalid")
        {
            lblStatus.Text = "UserName/Password is incorrect";
            txtUserName.Focus();
            txtUserName.Text = string.Empty;
            txtPassword.Text = string.Empty;
        }
    }

protected void btnLogout_Click(object sender, EventArgs e)
{
DateTime TimeoutSession=DateTime.Now.toString();
FormsAuthentication.SignOut();
}
}

推荐答案





最好设置会话时间清除,即使你想在关闭时设置它你可以参考下面的代码

Hi,

Its better to set time for session clear, even though you want to set it while closing you could refer the below code
function CloseSession( )
{
    //Trigger logout button click event to force to logout the application
    document.getElementById('btnLogout').click();
}
window.onbeforeunload = CloseSession;



希望这对你有所帮助。



问候,

RK


Hope this helps you a bit.

Regards,
RK


这篇关于如何在用户关闭浏览器后注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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