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();
}
}
直接 上代码:
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();
}
}
相关文章推荐
- .aspx 页面引用命名空间
- 解读ASP.NET 5 & MVC6系列教程(4):核心技术与环境配置
- Mac中体验ASP.NET 5 beta2的K gen代码生成
- ASP.Net MVC开发基础学习笔记:四、校验、AJAX与过滤器
- ASP.Net MVC开发基础学习笔记:三、Razor视图引擎、控制器与路由机制学习
- ASP.Net MVC开发基础学习笔记:二、HtmlHelper与扩展方法
- ASP.Net MVC开发基础学习笔记(1):走向MVC模式
- 解读ASP.NET 5 & MVC6系列教程(3):项目发布与部署
- 解读ASP.NET 5 & MVC6系列教程(2):初识项目
- mount 挂载 img
- 解读ASP.NET 5 & MVC6系列教程(1):ASP.NET 5简介
- ASP.NET的内置对象之二 Server
- 用数据库保存Session及创建ASPState数据库时出现的问题
- Causedby:java.lang.ClassNotFoundException:org.aspectj.lang.annotation.Around
- ASP.NET Web Api 2实现多文件打包并下载文件的实例
- ASP.NET的内置对象之一 Request
- ASP.NET(C#) Web Api通过文件流下载文件的实例
- asp.net写入日志到文本文件
- ASP.NET Page Life Cycle Events
- ASP.NET(C#) Web Api通过文件流下载文件的实例