C# mvc4中会话过期后无法返回登录页面

C# mvc4中会话过期后无法返回登录页面,c#,asp.net-mvc-4,session,action-filter,C#,Asp.net Mvc 4,Session,Action Filter,我已经创建了过滤器来检查会话,如果会话过期,我将重定向到登录页面。这是我下面的代码 public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpContext ctx = HttpContext.Current; if(HttpContext.Current.User.Identity.Name=="")

我已经创建了过滤器来检查会话,如果会话过期,我将重定向到登录页面。这是我下面的代码

 public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
            HttpContext ctx = HttpContext.Current;
           if(HttpContext.Current.User.Identity.Name=="")
            {
                FormsAuthentication.SignOut();
                filterContext.Result = new RedirectResult("~/Login/Index");
                return;
            }
            base.OnActionExecuting(filterContext);
        }
我装饰我的行动方法如下

 [SessionTimeOut]
  public PartialViewResult GetGridData(string client_id, string emp_id, string empciti_id, string Message)
它很好用。会话到期后,它将呈现登录页面。但我面临的问题是我的布局页面仍然出现在顶部。在中心显示我的登录页面。那么我如何解决这个问题呢?提前谢谢

我已经创建了过滤器来检查会话,如果会话过期,我将重定向到登录页面。这是我下面的代码

 public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
            HttpContext ctx = HttpContext.Current;
           if(HttpContext.Current.User.Identity.Name=="")
            {
                FormsAuthentication.SignOut();
                filterContext.Result = new RedirectResult("~/Login/Index");
                return;
            }
            base.OnActionExecuting(filterContext);
        }
你做得很糟。这不是好的做法


您已经有一个名为
AuthorizeAttribute
的筛选器属性。我建议使用它。还要检查一下这篇文章,其中谈到了在应用程序中实现授权/身份验证的简单方法

在~/Views/Login/Index.cshtml集合中-

Layout = null;

我删除了我创建的过滤器。我添加了authorized属性,它工作正常,但登录页面像以前一样只显示在中间,你说的“只显示中间”是什么意思?我添加了图像。布局页面也显示在顶部。该登录页面的下方显示。我仍然无法获取它。您只需要登录页面可见,而不需要其他内容?如果是这样,请确保登录/索引操作返回视图,并确保布局页面不包含任何其他需要验证的内容。