简单记录个人遇到的问题。。。。。。
方式一:利用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 秒



