简体   繁体   中英

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 . 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.

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

Layout = null;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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