微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

会话结束后,用C#代码制作一个简单的JavaScript Alert弹出窗口

如何解决会话结束后,用C#代码制作一个简单的JavaScript Alert弹出窗口

要做的是,我已经使用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");
                    }
                }
            }
        }
    }

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

有人可以帮忙吗?预先感谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。