我想在关闭浏览器时清除会话值,并更新状态以注销数据库 [英] i want to clear session values when the browser is closed and update the status to logout in database

查看:199
本文介绍了我想在关闭浏览器时清除会话值,并更新状态以注销数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我关闭浏览器并重新打开会话值时,便在global.asax(application_end)中编写了以下代码,会话值未清除并且状态在数据库中显示为空.

I wrote below code in global.asax(application_end) whenever i closed the browser and reopens the session values are not clearing and status is showing null in database.

string strlogout = "logout";
          //updatelogouttime();
    //     public void updatelogouttime()
    //{
        Empbusinessaccesslayer obj = new Empbusinessaccesslayer();
        obj.Empname = Session["Username"].ToString();
        obj.Ipaddress = Session["ipaddress"].ToString();
        DateTime dt = (DateTime)Session["logintime"];
        obj.Createddate = Convert.ToDateTime(Session["logindate"].ToString());
        obj.Jobposteddate = dt;
        obj.Comptypeid = int.Parse(Session["comptypeid"].ToString());
        obj.Curremployer = strlogout;
        obj.updateuserlogout(Session["Username"].ToString(), Session["ipaddress"].ToString(), Convert.ToDateTime(Session["logindate"].ToString()), dt, int.Parse(Session["comptypeid"].ToString()), strlogout);

        Session["Username"] = null;
        Session["empname"] = null;
        Session["comptypeid"] = null;
        Session.Contents.Clear();
        Session.Abandon();

推荐答案

或者,您也可以查看来自CP的以下链接:
如何在浏览器关闭时结束用户会话 [ ^ ]
Alternatively you can have a look at following link from CP:
How to end user session when browser closed[^]


在关闭浏览器时清除会话值
关闭浏览器实际上应该清除会话变量 [ ^ ]

您可以在window.onbeforeunload事件上添加更新查询.
clear session values when the browser is closed
Closing the browser should actually clear the session variables[^]

You can add update query on window.onbeforeunload event.


没有特定的方法可以执行此操作-这取决于所使用的浏览器以及用户的操作-如果您只是关闭接通PC的电源,或者Internet连接失败,那么您将永远不会收到关闭浏览器"信号,因此永远不会注销.

但是,您可以在JavaScript中处理浏览器的onbeforeunload事件(该事件应在IE和FF中起作用),并将其发送给服务器.如果他们没有启用javascript ...

最好重新设计系统以使其正常运行.
There is no certain way to do this - it depends on the browser used, and what the user does - if you just turns off the power to his PC, or his internet connection fails then you will never get the "close browser" signal, and so the log off will never occur.

However, you can handle the browser onbeforeunload event (which should work in IE and FF) in the javascript, and signal it to the server. If they don''t have javascript enabled though...

It would be better to redesign your system to work round it.


这篇关于我想在关闭浏览器时清除会话值,并更新状态以注销数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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