question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using ASP.Net Core, the sample didn't work, with SigninManager

See original GitHub issue

I am using the IdentityCore like following:

services.AddIdentityCore<ApplicationUser>()
                .AddUserStore()
                .AddSignInManager()
                .AddDefaultTokenProviders();

When I use the following code with it:

           services
                .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
                .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme);

            services.AddSingleton<IMultiTenantStore>((serviceProvider) =>
            {
                var cfg = serviceProvider.GetService<List<TenantConfiguration>>();
                return new TenantResolver(cfg.ToArray());
            });
            services.AddMultiTenant()
                .WithHostStrategy()
                .AddPerTenantCookieAuthentication();



public static MultiTenantBuilder AddPerTenantCookieAuthentication(this MultiTenantBuilder builder)
        {
            return builder.WithPerTenantOptions<CookieAuthenticationOptions>((options, tenantContext) =>
                {
                    // Set a unique cookie name for this tenant.         
                    options.Cookie.Name = tenantContext.Id + "-cookie";
                });
        }

I get the following error: InvalidOperationException: No sign-in authentication handler is registered for the scheme ‘Identity.Application’. The registered sign-in schemes are: cookies. Did you forget to call AddAuthentication().AddCookies(“Identity.Application”,…)?


Microsoft.AspNetCore.Authentication.AuthenticationService.SignInAsync(HttpContext context, string scheme, ClaimsPrincipal principal, AuthenticationProperties properties)
Microsoft.AspNetCore.Identity.SignInManager<TUser>.SignInAsync(TUser user, AuthenticationProperties authenticationProperties, string authenticationMethod)
Profile.Controllers.AccountController.Registreer(RegisterViewModel model, string returnUrl) in AccountController.cs

                        await signInManager.SignInAsync(user, isPersistent: false);

If I change the scheme to this:

services
                .AddAuthentication("Identity.Application")
                .AddCookie("Identity.Application");

I can log in. Am I configuring something wrong? I would rather not hard code this value, to this one value I can’t change.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
AndreSteenbergencommented, Oct 9, 2018

Ok, it is is SignInManager (https://github.com/aspnet/Identity/blob/c7276ce2f76312ddd7fccad6e399da96b9f6fae1/src/Identity/SignInManager.cs#L194)

So basically if you want to use the SigninManager you will need to use scheme:

services
                .AddAuthentication(IdentityConstants.ApplicationScheme)
                .AddCookie(IdentityConstants.ApplicationScheme);
0reactions
stale[bot]commented, Oct 5, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SignInManager dependency injection fails with ASP.NET ...
If I remove the SignInManager parameter from the constructor everything works fine. All the relevant examples I have seen online end up being ......
Read more >
SignInManager not working when injected to razor page
Hi, i'm having troubles getting SignInManager injected in a razor page , the signInManager.IsSignedIn(User) is alway false even if i'm loged ...
Read more >
Extending the ASP.NET Core 1.0 Identity SignInManager
In this post I show how we can extend and override the default behaviour of the ASP.NET Core 1.0 Identity SignInManager class to...
Read more >
ASP NET Core Identity UserManager and SignInManager
We use the generic parameter to specify the User class that these services should work with. At the moment, we are using the...
Read more >
Custom User Management in ASP.NET Core MVC ...
We will build a small yet practical implementation of Custom User Management in ASP.NET Core MVC with Identity. This will cover most of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found