Asp.net Session过期页面处理

时间:2021-11-29 23:28:01

效果如下图:

Asp.net Session过期页面处理


源码如下:

前端:

<script type="text/javascript">
        var i = 10;

        // 获取登录事件,并处理自动跳转
        window.onload = function windowload() {
            document.getElementById("time").innerText = i;
            document.getElementById("time2").innerText = i;
            JumpPage();
        }

        function JumpPage() {
            document.getElementById("time").innerText = i;
            document.getElementById("time2").innerText = i;
            // 计时为0后,立即跳转
            i--;
            if (i < 0) {
                location.replace("Login.aspx");
            }

            setTimeout("JumpPage()", 1000);
        }
    </script>

<div class="DIV1" style="font-family: 微软雅黑; font-size: small">
    <div class="DIV2" style="color:White;">错误提示:网页信息已过期,请重新登录!(Error: web information has expired, please login again.)</div>
    <div style="height:7px"></div>
        本页将在<span id="time" style="color: Blue"></span>秒后自动跳转至<a href="Login.aspx">登录页面</a>,如需立即跳转,请直接点击 <a href="Login.aspx" style="color: Blue">立即跳转>></a><br/>
        The page will be re-directed in <span id="time2" style="color: Blue"></span> seconds. Please wait a moment...  <a href="Login.aspx" style="color: Blue">Re-directed Now>></a>
        </div>

后端处理:在BasePage的Load事件中判断Session是否为空

if (Session["LoginEmployeeID"] == null)
            {
                Response.Clear();
                Response.Write("<script language=javascript>parent.location.href='../Account/SessionExpired.aspx'</script>");
                //Response.Write("<script language=javascript>window.open('../Account/SessionExpired.aspx');top.opener=null;top.close();</script>");
                Response.End();
            }