您的位置:首页 > 编程语言 > ASP

asp.net 登录超时跳转到登录页 后台实现

2016-06-23 16:05 543 查看
不管在子页面还是弹出窗中都能跳到登录页,这里提供了一种思路,最好是在前台实现,这里我是原来的项目,为了改动小所以后台实现。

直接 上代码:

            if (HttpContext.Current.Session["userid"] == null)

            {

                int count= HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.Split('\\','/').Length;

                if (count > 1)

                {

                    string msg = "系统超时,请重新登录!";

                    string loginPath = "Default.aspx?msg=" + msg;

                    while (count > 2) {

                        loginPath = "../" + loginPath;

                        count--;

                    }

                    HttpContext.Current.Session.Clear();

                    string script = @"<script type='text/javascript'>

function relogin(my,deep){

if(my.opener){

alert('" + msg + @"');

relogin(my.opener,deep);

my.close();

}

else if(my.location.pathname.toUpperCase().indexOf('DEFAULT.ASPX')>=0){

my.location.href='" + loginPath+@"'

}

else if(deep>0)

{

deep=deep-1;

relogin(my.parent,deep);

}}

relogin(window,5);</script>";

                    HttpContext.Current.Response.Write(script);

                    HttpContext.Current.Response.End();
                }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: