0
votes

In our ASP.NET MVC Application, when session get timed out , page give crash on components where we have Jquery AJAX calls, however if we manually load the page it log out and redirect to login page.

We want user to redirect to login page automatically when session get expired, we are using form authentication and have a CustomPrincipal defined.

1
Might be a duplicate question. stackoverflow.com/questions/5238854/…Sain Pradeep
Thanks @SainPradeep, but I want to log out the user and want to do it on application level not on Individual controller.ChupChapCharli
You can use a global Custom filter for this(AuthorizeFilter or ActionFilter).Sain Pradeep

1 Answers

1
votes

insert following code in global.asax

    public class SessionExpireAttribute : ActionFilterAttribute
    {
       public override void OnActionExecuting(ActionExecutingContext filterContext)
       {
          if (HttpContext.Current.Session["SessionId"] == null)
           {
            filterContext.Result = new RedirectResult("~/Home/Login");
            return;
        }
        base.OnActionExecuting(filterContext);
      }
    }

and in every controller call this attribute as following

   [SolutionName.MvcApplication.SessionExpire]
   public class HomeController : Controller
   {
   }