我想在认证之前显示一个弹出警告&会话超时。警告弹出窗口应该有选项来保持登录或注销。我几乎完成了功能,但有时单击保持登录按钮会将用户重定向到登录页面。 我已经设置了相同的身份验证和会话超时值。 我正在使用timeout插件来显示警告。 这就是我的代码的样子
timer = null;
$(document).ready(function () {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(EndRequestHandler);
SetTimeoutDialog();
});
// show warning message to users before session timeout
function SetTimeoutDialog() {
//clear previous timers
if (timer != null)
clearInterval(timer);
$.get('/GetRemainingTimeout.aspx', function (data) {
var timeout = parseInt(data);
timer = setInterval(function () {
$.timeoutDialog({ timeout: 0, countdown: 180, keep_alive_url: '/KeepSessionAlive.aspx', logout_url: '/Logout.aspx', logout_redirect_url: '/Login.aspx', restart_on_yes: false });
}, (timeout - 180000));
});
}
function EndRequestHandler(sender, args) {
SetTimeoutDialog();
}
此外,这就是GetRemainingTimeout.aspx.cs中的代码如何
protected void Page_Load(object sender, EventArgs e)
{
DateTime dateNow = DateTime.Now;
if (HttpContext.Current.User.Identity is FormsIdentity)
{
HttpCookie authCookie = this.Context.Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
double leftMilliSeconds = (authTicket.Expiration - dateNow).TotalMilliseconds;
// Control in MasterPage, where I setting value and then taking for JavaSript to CountDown message
Response.Write(leftMilliSeconds > 0 ? leftMilliSeconds.ToString() : "0");
}
}