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

问题描述

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

推荐答案

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


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

08-05 09:53