Wie logout Benutzer in OWIN ASP.NET MVC5

Habe ich eine standard - AccountController Klasse von ASP.NET MVC5 Projekt.
Wenn ich versuche, Benutzer Abmelden, das ich mich vor einem Fehler coz HttpContext ist null. (Ich meine hier HttpContext.GetOwinContext().Authentifizierung ist null)

, So kann ich nicht bekommen, wie können wir den Abmelden-Benutzer, wenn die Sitzung endet...

In global.asax ich habe diese

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)
            {
            }
}

AccountController

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; }
}

Start.Auth.cs hat

 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")
            });
}

InformationsquelleAutor Academy of Programmer | 2014-10-03

Schreibe einen Kommentar