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

  • Post author:
  • Post category:其他


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

直接 上代码:

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();

}

}



版权声明:本文为sqlite_me原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。