0

我想要做的是,我在 Global.asax.cs 文件中使用了一个函数来检测用户的登录会话何时过期,如果过期,则应将用户重定向到登录页面,代码如下所示:

protected void Session_Start(object sender, EventArgs e)
    {
        if (Context.Session != null)
        {
            if (Session.IsNewSession)
            {
                HttpCookie newSessionIdCookie = Request.Cookies["ASP.NET_SessionId"];
                if (newSessionIdCookie != null)
                {
                    string newSessionIdCookieValue = newSessionIdCookie.Value;
                    if (newSessionIdCookieValue != string.Empty)
                    {
                       //I want to let the client side page to pop-up an alert to indicate the user 
                       //that the session is expired.

                        Response.Write("<script>alert('Your Session is out, please re-login!');</script>");

                        // This means Session was timed Out and New Session was started
                        Response.Redirect("Login.aspx");
                    }
                }
            }
        }
    }

但是,我当前代码的问题是,当会话过期时,页面将直接重定向,根本没有弹出警报。

有人可以帮忙吗?提前致谢!

4

0 回答 0