InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found in ASP.NET Core 2.0

13,959

You need the following in Startup.cs:

services.AddAuthentication(IISDefaults.AuthenticationScheme);
Share:
13,959

Related videos on Youtube

Mischa Morf
Author by

Mischa Morf

Updated on June 04, 2022

Comments

  • Mischa Morf
    Mischa Morf almost 2 years

    Im using ASP.net core 2 in an mvc web application. Im currently authorizing from an AD group on one Controller action, and it worked fine on the localhost so far. Now after publishing, instead of getting the log in window I get the following error:

    InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found.

    This is how I authorize the AD role.

    [Authorize(Roles = "Domain Users")]
    

    Do i need to add something to the startup.cs or am I missing something else?

    • Mischa Morf
      Mischa Morf about 5 years
      lacking time right now to do that. U know if there is an easy way to fix this though? @nyulan
    • nyulan
      nyulan about 5 years
      show startup.cs
    • Chris Pratt
      Chris Pratt about 5 years
      @nyulan: That doesn't work in ASP.NET Core. AuthorizeAttribute is merely a placeholder now. The actual work of auth happens via other facilities, i.e. there is no AuthorizeCore method to override.
  • Mischa Morf
    Mischa Morf about 5 years
    worked thanks. Any idea on a action that logs that authorized user out again?
  • Chris Pratt
    Chris Pratt about 5 years
    Depends on your exact scenario. I don't think you can in a Windows Auth scenario. But, perhaps using ADFS as a provider.