会话超时在global.asax中无法正常工作

时间:2018-06-29 05:03:37

标签: asp.net

在我的asp.net项目中,我在session.global中有一个事件作为会话结束,该事件在会话超时时触发,在这种情况下,我正在调用一个存储过程来更新表中的注销时间和标志。但是,当用户登录时,在工作后用户关闭浏览器,并且在第二天尝试首次登录时,消息会显示该用户已经登录,但是当他再次尝试登录时,他可以登录。 / p>

请解决其生产问题

<%@ Application Language="C#" %>

<script runat="server">
void Application_Start(object sender, EventArgs e) 
{

}

void Application_End(object sender, EventArgs e) 
{ 
    Admin.User_Role objUserRole = new Admin.User_Role();

    objUserRole.SchemaName = 
(string)CBase.TripleDESDecode(Application["SchemaName"].ToString(), 
CBase.EncryptionKey);
    if (Session["UserId"] != null)
        objUserRole.UserId = (string)Session["UserId"];

    objUserRole.ModifiedDate = Convert.ToDateTime(CBase.GetServerDateTime());

    try
    {
        objUserRole.funcUpdateLoggedIn();
    }
    catch (Exception ex)
    {
        //Response.Redirect(HttpUtility.UrlEncode("Logout.aspx"), false);
    }
}
void Application_Error(object sender, EventArgs e)
{
    Exception ex = this.Server.GetLastError().GetBaseException();

}
public HttpSessionState GetSession()
{

    if (HttpContext.Current != null)
    {
        return HttpContext.Current.Session;
    }
    else
    {
        return this.Session;
    }
}
void Session_Start(object sender, EventArgs e) 
{


}
void Session_End(object sender, EventArgs e) 
{
    Admin.User_Role objUserRole = new Admin.User_Role();

    string userid = Convert.ToString(GetSession()["UserId"]);
    objUserRole.UserId = (string)CBase.TripleDESDecode(userid, 
CBase.EncryptionKey);
    objUserRole.ModifiedDate = Convert.ToDateTime(CBase.GetServerDateTime());
   // objUserRole.funcUpdateLoggedIn();


    try
    {
        objUserRole.funcUpdateLoggedIn();

    }
    catch (Exception ex)
    {
        //Response.Redirect(HttpUtility.UrlEncode("Logout.aspx"), false);
    }


   finally 
    {
        Session.Abandon();
        Session.Clear();
    }

}

</script>

0 个答案:

没有答案