Session expiration issue in ASP.NET MVC
<p>Hi I have some issues with ASP.NET MVC session state which is not expiring after I implement the following piece of code and put the attributes over the methods.</p>

<pre><code>public sealed class SessionActionFilterAttribute : ActionFilterAttribute
{
    public override void  OnActionExecuting(ActionExecutingContext filterContext)
    {
        HttpContext ctx = HttpContext.Current;
        //Check if session is supported 
        if (ctx.Session != null)
        { 
            //Check if the session is new
            if (ctx.Session.IsNewSession)
            {
                //If it says it is a new session but an existing cookie exists
                //then it must have timed out
                string sessionCookie = filterContext.HttpContext.Request.Headers["Cookie"]; 
                if ((sessionCookie != null) &amp;&amp; (sessionCookie.IndexOf("ASP.NET_SessionId", StringComparison.OrdinalIgnoreCase) &gt;= 0))
                {
                    //Redirect to the login page
                    ctx.Response.Redirect("~/Home/Index", true);
                    ctx.Response.End();
                }
            }
        }
        base.OnActionExecuting(filterContext);
    }
}
</code></pre>

<p>The issue is that the Redirection request is not executing and the Action which has SessionActionFilter Attribute executes. This method uses session variables which are expired and results in error. </p>

<p>Can anybody tell what I am missing?</p>

<p>Thanks a lot in advance!!</p>
