不管在子页面还是弹出窗中都能跳到登录页,这里提供了一种思路,最好是在前台实现,这里我是原来的项目,为了改动小所以后台实现。
直接 上代码:
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();
}
}