skip to Main Content

I’m developing an ASP.NET Core application with Razor Pages, and I’ve implemented registration and login features. However, I’m facing a problem with the logout functionality. When a user clicks on the logout button, the user is supposed to be redirected to a specific page, but instead, I’m encountering a white screen issue.

The current behavior is as follows: after clicking the logout button, the browser is redirected to "https://localhost:7082/signout-oidc?state=longstring", where I am greeted with a white screen. My expectation is to redirect the user to the home page or a specified page after logging out.

Here is the relevant code:

Logout button in Razor Page:

<a href='@Url.Action("SignOut", "Account", new { Area = "MicrosoftIdentity" })' class="logout-button">Logout</a>

SignOut action in the Account controller:

public async Task<IActionResult> SignOut()
{
    await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
    return RedirectToPage("/Index");
}

I suspect the issue might be related to the way the sign-out process is being handled or maybe the redirection after the sign-out is not correctly configured. The redirect for sign-out is set to "https://localhost:7082/signout-oidc", but it doesn’t seem to work as intended.

Has anyone encountered a similar issue or can provide insights into what I might be doing wrong? How can I ensure that after the sign-out process, the user is redirected to a designated page (like the home page) instead of being left on a white screen?

Any help or suggestions would be greatly appreciated!

2

Answers


  1. Chosen as BEST ANSWER

    I was using this service configure in my Program.cs. I deleted this codeblock and it works fine now.

    builder.Services.Configure<OpenIdConnectOptions>(
    OpenIdConnectDefaults.AuthenticationScheme,
    options => {
        options.SignedOutCallbackPath = "/signout-oidc";
        options.SignedOutRedirectUri = "/Ausloggen";
    });
    

  2. You could specify signout property in singoutasync method.

            public async Task SignOut()
            {
                var props = new AuthenticationProperties()
                {
                    RedirectUri = "/Index"
                };
                await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme, props);
            }
    

    You could also set a global redirect url in program.cs

    builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
                    .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
                    {               
                        options.Events.OnSigningOut = (context) =>
                        {
                            context.Response.Redirect("/Index");                                
                            return Task.CompletedTask;
                        };
                    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search