If someone uses Scaffolding (they use Razor Page files), here's how to fix it according to Akhilesh's answer:
In the \ Identity \ Pages \ Account \ Logout.cshtml areas:
First add the IIdentityServerInteractionService service:
IIdentityServerInteractionService _interaction; public LogoutModel(SignInManager<IdentityUser> signInManager, ILogger<LogoutModel> logger, IIdentityServerInteractionService _interaction) { _signInManager = signInManager; _logger = logger; this._interaction = _interaction; }
You may need to add OnGet() support, the logic may vary depending on your case, in my case, Get or Post does not matter:
public async Task<IActionResult> OnGet(string returnUrl = null) { return await this.OnPost(returnUrl); }
Add LogoutId logic to OnPost:
public async Task<IActionResult> OnPost(string returnUrl = null) { await _signInManager.SignOutAsync(); _logger.LogInformation("User logged out."); var logoutId = this.Request.Query["logoutId"].ToString(); if (returnUrl != null) { return LocalRedirect(returnUrl); } else if (!string.IsNullOrEmpty(logoutId)) { var logoutContext = await this._interaction.GetLogoutContextAsync(logoutId); returnUrl = logoutContext.PostLogoutRedirectUri; if (!string.IsNullOrEmpty(returnUrl)) { return this.Redirect(returnUrl); } else { return Page(); } } else { return Page(); } }
source share