栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

C# Session超时返回重新Login与IFrame内部重定向

C# Session超时返回重新Login与IFrame内部重定向

简单记录个人遇到的问题。。。。。。

方式一:利用Sessin进行超时返回重新登陆:

1.首先在Web.config中 标签下添加如下配置:

 

timeout的单位为 min, timeout="1" 表示1分钟

2.在Global.asax.cs下进行添加如下代码:

void Application_PostRequestHandlerExecute(object sender, EventArgs e)
        {
            // Code that runs on application startup
            string strPage = Request.Path.ToUpper();
            if (strPage.Contains("/LOGIN/") || strPage.Contains("/REQUESTDATA/")) return;
            if (Session != null && Session["CurrentUser"] == null)
            {
                //cookiesHelper.Addcookie("UserID", System.DateTime.Now.AddDays(-1));
                Response.Write(" ");               
            }
        }
		

void Session_Start(object sender, EventArgs e)
	{
		// Code that runs when a new session is started

	}
	
void Session_End(object sender, EventArgs e)
{
	// Code that runs when a session ends. 
	// Note: The Session_End event is raised only when the sessionstate mode
	// is set to InProc in the Web.config file. If session mode is set to StateServer 
	// or SQLServer, the event is not raised.
}

3.在LoginController.cs中添加如下代码,如要是给session赋值。

 
  public string CheckUserLogin(string loginName, string loginPassword, string loginFab)  //内部用户登陆
        {
            string msg;
            try
            {
                string userid;
                string ip = string.IsNullOrEmpty(Request.ServerVariables["REMOTE_ADDR"]) ? "" : Request.ServerVariables["REMOTE_ADDR"];
                if (new UserBLL().LoginCheck(loginName, loginPassword, loginFab, ip, out msg, out userid))
                {
                    cookiesHelper.Setcookie("UserID", AES.EncryptStr(userid));
                    Session["CurrentUser"] = userid;
                    Session["LoginFab"] = loginFab;
                    cookiesHelper.Setcookie("LoginFab", loginFab);
                    return "OK";
                }
                else
                {
                    return msg;
                }

            }
            catch (Exception ex)
            {
                logs.Error("", ex);
                return ex.Message;
            }
        }

方式二: 利用JS实现一定时间内无操作,进行页面跳转。

var lastTime = new Date().getTime();
var currentTime = new Date().getTime();
var timeOut = 1 * 20 * 1000; // 20 秒
$(function () {
	$(document).mousemove(function () {
		lastTime = new Date().getTime();
	});
});
function testTime() {
	currentTime = new Date().getTime();
	if (currentTime - lastTime > timeOut) {
		console.log("超时!!!!!!!!!!")
		//window.location.href = "/Login/Index";
		//alert(document.cookie);
		parent.location.replace("/Login/Index");
	}
}
window.setInterval(testTime, 1000); // 1 秒

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/283156.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号