简体   繁体   English

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

[英]Unable to return to login page after session expires in mvc4

I have created filter to check session and if it is expired i am redirecting to login page. 我创建了过滤器来检查会话,如果会话已过期,我将重定向到登录页面。 This is my below code. 这是我的下面的代码。

 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);
        }

I decorated my action method as below. 我将动作方法装饰如下。

 [SessionTimeOut]
  public PartialViewResult GetGridData(string client_id, string emp_id, string empciti_id, string Message)

It works fine. 工作正常。 After session expires it will render login page. 会话过期后,它将呈现登录页面。 But problem i am facing is my layout page still appeares in top. 但是我面临的问题是我的布局页面仍然出现在顶部。 In center my login page appears. 在中心出现我的登录页面。 我的登录页面出现在中心。我已附上图片。 so how can i fix this issue? 所以我该如何解决这个问题? thanks in advance. 提前致谢。

I have created filter to check session and if it is expired i am redirecting to login page. 我创建了过滤器来检查会话,如果会话已过期,我将重定向到登录页面。 This is my below code. 这是我的下面的代码。

You're doing it bad. 你做得不好 This is not the the good practice. 这不是一个好习惯。

You already have an filter attribute called AuthorizeAttribute . 您已经有一个名为AuthorizeAttribute的过滤器属性。 I recommend to use it. 我建议使用它。 And also check this link which talk about ASP.Net Identity the easy way to implement authorization/authentication in your application. 并检查此链接 ,该链接谈论ASP.Net Identity是在应用程序中实现授权/身份验证的简便方法。

在〜/ Views / Login / Index.cshtml设置中-

Layout = null;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM