Open Closed

Redirect to custom post logout page #9817


User avatar
0
adamjenkins created

We are using the microservice architecture and need to support a different post logout redirect uri depending on a certain condition e.g. (old customer go to X url).

Currently the post logout goes to the home page (no settings have changed) but as our home page requires authentication you get redirected to the login screen.

How do I make it so I can redirect the user to a different url? I have tried specifying the return url in the logoutasync method within the account controller but that is ignored.

ABP 9.3.1 OpenIddict


5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I have tried specifying the return url in the logoutasync method within the account controller but that is ignored.

    Can you share your logout method code?

    Thanks.

  • User Avatar
    0
    adamjenkins created
    public class AccountController(ILegacyTenantAppService legacyTenantAppService)
        : AbpAccountImpersonationChallengeAccountController
    {
        public override async Task<ActionResult> LogoutAsync(string returnUrl = "", string returnUrlHash = "")
        {
            var tenant = await legacyTenantAppService.GetLegacyIdAsync();
            if (returnUrl.IsNullOrEmpty() &&tenant.LegacyId > 0)
            {
                returnUrl = $"https://domain.com/login/{tenant.LegacyId}?logout=1";
            }
    
            return await base.LogoutAsync(returnUrl, returnUrlHash);
        }
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The base class will call the GetRedirectUrlAsync.

    Can you debug to check if your returnUrl is set correctly?

    Thanks.

    [HttpGet]
    public virtual async Task<ActionResult> LogoutAsync(string returnUrl = "", string returnUrlHash = "")
    {
        await HttpContext.SignOutAsync();
    
        if (HttpContext.User.Identity?.AuthenticationType == AuthenticationType)
        {
            return await RedirectSafelyAsync(returnUrl, returnUrlHash);
        }
    
        return SignOut(new AuthenticationProperties { RedirectUri = await GetRedirectUrlAsync(returnUrl, returnUrlHash) }, ChallengeAuthenticationSchemas);
    }
    
    
  • User Avatar
    0
    adamjenkins created

    Looks like even though the return url is being passed in it then checks against options to allowed urls.

    As this isn't a local url and is unique to each tenant I have made a new local url that redirects after the fact.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Great 👍

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on September 01, 2025, 08:37