3

I receive the above error after I have successfully registered a user and confirmed authentication. The error occurs when I try to call

await _signInManager.SignInAsync(applicationUser, isPersistent);

I first assign the service to the IServiceCollection with this:

services.AddIdentity<ApplicationUser, IdentityRole<int>>(
            config => { config.User.RequireUniqueEmail = true;
                config.Cookies.ApplicationCookie.LoginPath = "/Account/Login";
                config.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents()
                {
                    OnRedirectToLogin = async ctx =>
                    {
                        if (ctx.Request.Path.StartsWithSegments("/api") && ctx.Response.StatusCode == 200)
                        {
                            ctx.Response.StatusCode = 401;
                        }
                        else
                        {
                            ctx.Response.Redirect(ctx.RedirectUri);
                        }
                        await Task.Yield();
                    }
                };
            }).AddEntityFrameworkStores<VisualJobsDbContext, int>()
          .AddDefaultTokenProviders();

and in my Config method of startup I call app.UseIdentity(); before the call to app.UseMvc

if I change my call to be:

var myVal = await _signInManager.PasswordSignInAsync(applicationUser, password, true, false);

them myVal is goes to 'Failed' I do not get any error thrown

bilpor
  • 3,467
  • 6
  • 32
  • 77

1 Answers1

0

Try to add app.UseIdentity(); into Startup.cs Configure method as in this answer No authentication handler is configured to authenticate for the scheme: Microsoft.AspNet.Identity.External

Community
  • 1
  • 1
A. Gladkiy
  • 3,134
  • 5
  • 38
  • 82
  • Please don't add the same answer to multiple questions. Answer the best one and flag the rest as duplicates. See http://meta.stackexchange.com/questions/104227/is-it-acceptable-to-add-a-duplicate-answer-to-several-questions – Bhargav Rao Nov 08 '16 at 11:33
  • It appears that UseIdentity() is now deprecated. – Timothy Lee Russell Aug 30 '19 at 06:55