Redirect after Session Timeout in MVC Action Filter
<p>I have to redirect to home page after session timeout in mvc 5 application. I am using following code :</p>

<pre><code> public class SessionExpireAttribute : ActionFilterAttribute
    {

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {

            var currentEnvironment = EnvironmentUtility.GetSession().Get&lt;Environment&gt;();
            if (currentEnvironment == null)
            {
                filterContext.Result = new RedirectResult("~/Home/Index");
            }
            base.OnActionExecuting(filterContext);
        }

    }
</code></pre>

<p>In the controller, I have below code :</p>

<pre><code>[SessionExpire]
public ActionResult Submit()
{
    var urlReferrer = this.Request.UrlReferrer;
    if (urlReferrer != null)
    {
     return this.Redirect(urlReferrer.ToString());
    }
    else
    {
        return View();
    }
}
</code></pre>

<p>After the submit button is clicked, the page is redirecting to another page using javascript code as like below :</p>

<pre><code> function commitButtonClickedHandler()
{
       window.location.href = "@Url.Content("~/Working/NextPage")";
}
</code></pre>

<p>And the NextPage is like below :</p>

<pre><code>public ActionResult NextPage()
        {
            return this.View();
        }
</code></pre>

<p>What my requirement is after session timeout, when you click the submit button it should check seesion expiration. If it is expired , then it should be redirected to NextPage as like in SessionExpireAttribute. Else it should continue the process .But problem is after session timeout, the page is still redirecting to NextPage() action . Kindly help me to fix this.
Thank you.</p>