Asp.net mvc 会话超时时,我的页面未刷新-MVC4项目

Asp.net mvc 会话超时时,我的页面未刷新-MVC4项目,asp.net-mvc,Asp.net Mvc,我已经在web.Config文件中设置了会话时间,在会话超时后,我希望我的页面自动刷新并重定向到登录页面,但没有发生,请按如下所述查找我的代码:-请帮助我,我已经尝试了将近一周,但没有任何进展 HttpContext ctx = HttpContext.Current; if (ctx.Session != null) { // check if a new session id was generated if (ctx.Session.IsNewSession) {

我已经在
web.Config
文件中设置了会话时间,在会话超时后,我希望我的页面自动刷新并重定向到登录页面,但没有发生,请按如下所述查找我的代码:-请帮助我,我已经尝试了将近一周,但没有任何进展

HttpContext ctx = HttpContext.Current;

if (ctx.Session != null)
{
    // check if a new session id was generated
    if (ctx.Session.IsNewSession)
    {
        HttpContext ctx1 = HttpContext.Current;
        // check  sessions here
        if (ctx.Session["UserName"] == null || !filterContext.HttpContext.Request.IsAuthenticated)
        {
            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                FormsAuthentication.SignOut();
                filterContext.Result = new RedirectResult("~/Authentication/Logon");
                base.OnActionExecuting(filterContext);
            }
        }
    }
}

会话仅在服务器上超时。您的页面永远不会自动刷新。您需要在浏览器中实现轮询机制,以检查会话可用性并相应刷新。

让您的
表单用于身份验证。注销()执行?检查
Session[“UserName”]
在超时期间是否有值,如果该值不为空,则请求
。IsAuthenticated
从未被检查过。非常感谢您,您能帮我怎么做吗?请参阅此处的正确答案