Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

CookieAuthentication stopped working

$
0
0

This was working fine in my application last week (I deployed it to a server last week and that version is working fine), however it's not working in Visual Studio now.

In startup.cs I have :

            app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AuthenticationScheme = "Cookies",
                LoginPath = new PathString("/login"),
                AccessDeniedPath = new PathString("/login"),
                AutomaticAuthenticate = true,
                AutomaticChallenge = true
            });

There are 2 problems now, if I browse to a page whose controller action is flagged as [Authorize] then instead of redirecting me to /login (whiich it did previously) it's not returning a page with a 401 Unauthorized.

Also this code that runs at the point of succesfully logging in :

                var claims = new List<Claim>
                {
                    new Claim("username", model.EmailAddress)
                };

                var identity = new ClaimsIdentity(claims, "password");
                var principal = new ClaimsPrincipal(identity);

                await HttpContext.Authentication.SignInAsync("Cookies", principal);

The last line of code above causes this exception now : System.InvalidOperationException: 'No authentication handler is configured to handle the scheme: Cookies'

I really can't think of anything I have changed to stop it working.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>