My ASP.Net Core MVC project has been working fine for the past two years or so. It basically uses the Login/Logout code that is generated by the Visual Studio template from that time. My logout code looks like this:
[HttpGet]
public async Task<IActionResult> Logout()
{
await _signInManager.SignOutAsync();
_logger.LogInformation("User logged out.");
return RedirectToAction(nameof(HomeController.Index), "Home");
}
I noticed yesterday that this code does not actually log me out anymore - it redirects me to the home page, but the login link says "User Portal" instead of "Log In" as expected, and I can navigate to restricted pages. _signInManager.IsSignedIn(User); returns true in my Razor views.
After researching and trying things for several hours, I tried publishing to my IIS staging server, and the code still works as expected once it is published to IIS. It seems to fail only while I am debugging in Visual Studio using IIS Express. It is worth noting that I just updated to version 16.5.1 around the time that it broke, so I suspect that it has something to do with this version of VS. I can't remember what version I was on before, but it was probably a few months old.
I have tried the ideas in the following links without success:
ASP.NET Core Identity 2.0 SignoutAsync is not logging out user if the user signed in with Google
https://github.com/dotnet/AspNetCore.Docs/issues/6439
https://mcguirev10.com/2018/01/26/signoutasync-and-identity-server-cookies.html
(Long story short on the links: the following change does not help:)
// does not work
await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme);
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme, new AuthenticationProperties
{
RedirectUri = "/Home/Index"
});
Any help would be greatly appreciated! This is completely derailing me because I log in and out frequently to test different user permissions...