title: How to logout user in OWIN ASP.NET MVC5
body: <p>I have got a standard <strong>AccountController</strong> class of <em>ASP.NET MVC5 project.</em>
  When I try to log out user I am facing an error coz <code>HttpContext</code> is <code>null</code>. (I mean here <code>HttpContext</code><strong>.GetOwinContext().Authentication</strong> is null)</p>
  
  <p><strong>So I cannot get how we can logout user when session ends...</strong></p>
  
  <p>In <strong>global.asax</strong> I have got this</p>
  
  <pre><code>protected void Session_Start(object sender, EventArgs e)
  {
       Session.Timeout = 3; 
  }
  
  protected void Session_End(object sender, EventArgs e)
  {
              try
              {
                   var accountController = new AccountController();
                   accountController.SignOut();
              }
              catch (Exception)
              {
              }
  }
  </code></pre>
  
  <p><strong>AccountController</strong></p>
  
  <pre><code>public void SignOut()
  {
        // Even if I do It does not help coz HttpContext is NULL
        _authnManager = HttpContext.GetOwinContext().Authentication;    
  
      AuthenticationManager.SignOut();
  
  
  }
  
  private IAuthenticationManager _authnManager;  // Add this private variable
  
  
  public IAuthenticationManager AuthenticationManager // Modified this from private to public and add the setter
  {
              get
              {
                  if (_authnManager == null)
                      _authnManager = HttpContext.GetOwinContext().Authentication;
                  return _authnManager;
              }
              set { _authnManager = value; }
  }
  </code></pre>
  
  <p><strong>Startup.Auth.cs</strong>  has</p>
  
  <pre><code> public void ConfigureAuth(IAppBuilder app)
          {
              // Enable the application to use a cookie to store information for the signed in user
              app.UseCookieAuthentication(new CookieAuthenticationOptions
              {
                  ExpireTimeSpan = TimeSpan.FromMinutes(3),
                  AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                  LoginPath = new PathString("/Account/Login")
              });
  }
  </code></pre>