June 28, 2017 by Anuraj
This post is about ASP.NET Core authentication, which throws an InvalidOperationException - No authentication handler is configured to handle the scheme Cookies. In ASP.NET Core 1.x version, the runtime will throw this exception when you are running ASP.NET Cookie authentication. This can be fixed by setting
options.AutomaticChallenge = true in the Configure method.
Here is the full code.
And here is the SignIn method.
Recently I upgraded on of ASP.NET Core 1.x solution to ASP.NET Core 2.0. In ASP.NET Core 2.0, ASP.NET Core team changed the authentication methods and now there is nothing like
UseCookieAuthentication. I got some compilation issues with the existing solution. Since most of the documentation it only talking about ASP.NET 1.x, I had to spent time, and I fixed it.
Here is the new Startup.cs code for authentication.
And in the configure method, you need to use
But when I am running, I got the same exception.
After spending sometime, I figured out the issue. You don’t need to call the
HttpContext.Authentication.SignInAsync method. Instead you need to call the
HttpContext.SignInAsync method for authentication.
Here is the updated Signin code.
Happy Programming :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub