Home > Software design >  Getting error when i logout, No AuthenticationScheme was specified
Getting error when i logout, No AuthenticationScheme was specified

Time:12-22

working on a small asp.net mvc project there i know got the login and registerform complete. But i got a litle bit problem with my signout/logout buton,

Im getting this error:

InvalidOperationException: No authenticationScheme was specified, and there was no DefaultSignOutScheme found. The default schemes can be set using either AddAuthentication(string defaultScheme) or AddAuthentication(Action configureOptions).

And my controller Logout looks like this,

   public async Task<IActionResult> Logout()
        {
            await HttpContext.SignOutAsync();
            HttpContext.Session.SetString(SDApi.SessionToken, "");

            return RedirectToAction("Index", "Home");
        }

It says that my code is wrong on ,

await HttpContext.SignOutAsync();

You got any clue what might be wrong here or what iam missing :)? following a tutorial and i made exactly the same thing...

CodePudding user response:

i solved this after days of head scratching. In your Program.cs, dont forget to add DefaultScheme... I will copy and paste my code that helped me.

builder.Services.AddAuthentication
    (options =>
    {
        options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = "oidc";
    })
              .AddCookie(options =>
              {
                  options.Cookie.HttpOnly = true;
                  options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
                  options.LoginPath = "/Auth/Login";
                  options.AccessDeniedPath = "/Auth/AccessDenied";
                  options.SlidingExpiration = true;
              });
  • Related