I have tried every way possible, but I am still not able to logout the current user. Currently I have the following code:
_authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
string sKey = (string)HttpContext.Current.Session["user"];
string sUser = Convert.ToString(HttpContext.Current.Cache[sKey]);
HttpContext.Current.Cache.Remove(sUser);
HttpContext.Current.Session.Clear();
HttpContext.Current.Response.Cookies.Clear();
HttpContext.Current.Request.Cookies.Clear();
HttpContext.Current.Session.Abandon();
After this, the session is still not cleared. Any ideas?
Authentication startup:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
SignIn Code:
public override ApplicationUser Handle([NotNull]LoginCommand command)
{
var user = _userManager.Find(command.Login, command.Password);
if (user == null)
{
throw new RentalApplicationValidationException("No valid login");
}
_authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
var identity = _userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
_authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity);
return user;
}