0

I am using identityserver4 for my web application. I am trying to redirect to the my MVC client, but it didn't work as expected.Currently it redirected as following

localhost:44396/Account/Login?logoutId=CfDJ8EJf06VwS5JNrKjxoskwu06e9wy1VhZ_t8NW7L8TBFsx9LBFSRBsm9aZImm_ZmK5GIRaaU_-0W5fktg-Nv88fwMuMnjsk1N-d4LzY1y8VSPHUlGJldUjBejAHkrVc-

I tried to fix the issue with this answer

Logout Method in MVC controller

public async Task Logout()
{
  await HttpContext.SignOutAsync("Cookies");
  await HttpContext.SignOutAsync("oidc");
}

Account Controller:

    [HttpGet]
    public async Task<IActionResult> Logout(string logoutId)
    {
        
        var vm = await BuildLogoutViewModelAsync(logoutId);

        if (vm.ShowLogoutPrompt == false)
        {
            
            return await Logout(vm);
        }

        return View(vm);
    }
    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Logout(LogoutInputModel model)
    {
        var vm = await BuildLoggedOutViewModelAsync(model.LogoutId);

        if (User?.Identity.IsAuthenticated == true)
        {
            // delete local authentication cookie
            await _signInManager.SignOutAsync();
            

            await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
        }

        
        if (vm.TriggerExternalSignout)
        {
            
            string url = Url.Action("Logout", new { logoutId = vm.LogoutId });

            
            return SignOut(new AuthenticationProperties { RedirectUri = url }, vm.ExternalAuthenticationScheme);
        }
        if (vm.AutomaticRedirectAfterSignOut &&
           !string.IsNullOrWhiteSpace(vm.PostLogoutRedirectUri))
            return Redirect(vm.PostLogoutRedirectUri);

        return Redirect(vm.PostLogoutRedirectUri);
    }

How to solve this issue.

MRX
  • 3
  • 2
  • Please check the return URL (such as: PostLogoutRedirectUris), form the error message, it seems that at present, it will redirect to `localhost:44396/Account/Login`. – Zhi Lv Feb 25 '21 at 07:45
  • @Zhi Lv I checked it but no errors are found – MRX Feb 25 '21 at 10:12

0 Answers0