ASP.net MVC 5 Session is not clearing after calling Abandon()

Viewed 1807

MVC noob here.

I currently have this code that fires off my HomeController when a page loads via AJAX:

namespace ETTData.Controllers
{
  public class HomeController : Controller
  {
    [HttpPost]
    public ContentResult clearSessions()
    {
        var currentSession = System.Web.HttpContext.Current.Session;

        System.Diagnostics.Debug.WriteLine("BEFORE: " + currentSession.Timeout);

        currentSession.Abandon();
        //currentSession.RemoveAll();
        //currentSession.Clear();

        System.Diagnostics.Debug.WriteLine("AFTER : " + currentSession.Timeout);

        return new ContentResult { Content = "OK", ContentType = "text/plain" };
    }
  }
}

The output of the debug.WriteLine is:

BEFORE: 35

AFTER : 35

So as you can see it has 35 on the BEFORE but also has 35 for the AFTER when it shouldnt equal anything since I used currentSession.Abandon(); prior to calling that output.

I am setting the session timeout via the Global.asax.cs file:

namespace ETTData
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Session_Start(Object sender, EventArgs e)
        {
            HttpContext.Current.Session.Timeout = 35;
        }
    }
}

So saying all that - I'm at a loss as to why its not clearing the session...

2 Answers
Related