相关疑难解决方法(0)

尝试激活'AuthController'时无法解析类型'Microsoft.AspNetCore.Identity.UserManager`的服务

我在登录控制器中收到此错误.

InvalidOperationException:尝试激活'Automobile.Server.Controllers.AuthController'时,无法解析类型'Microsoft.AspNetCore.Identity.UserManager`1 [Automobile.Models.Account]'的服务.

这是Auth Controller构造函数:

private SignInManager<Automobile.Models.Account> _signManager;
    private UserManager<Automobile.Models.Account> _userManager;

    public AuthController(UserManager<Models.Account> userManager,
                          SignInManager<Automobile.Models.Account> signManager)
    {
        this._userManager = userManager;
        this._signManager = signManager;
    }
Run Code Online (Sandbox Code Playgroud)

这是在startup.cs中的ConfigureServices:

public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddApplicationInsightsTelemetry(Configuration);
        services.Configure<AppConfig>(Configuration.GetSection("AppSettings"));

        //var provider = HttpContext.ApplicationServices;
        //var someService = provider.GetService(typeof(ISomeService));


        services.AddDbContext<Providers.Database.EFProvider.DataContext>(options => options
            .UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
                 b => b.MigrationsAssembly("Automobile.Server")
            ));


        services.AddIdentity<IdentityUser, IdentityRole>(options =>
        {
            options.User.RequireUniqueEmail = false;
        })
        .AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
        .AddDefaultTokenProviders(); 
        //services.AddScoped<SignInManager<Automobile.Models.Account>, SignInManager<Automobile.Models.Account>>();
        //services.AddScoped<UserManager<Automobile.Models.Account>, UserManager<Automobile.Models.Account>>();

        services.AddMvc();
        App.Service = services.BuildServiceProvider();

        // Adds a default in-memory implementation of IDistributedCache.
        services.AddDistributedMemoryCache();

        services.AddSession(options …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc asp.net-core asp.net-core-identity

63
推荐指数
5
解决办法
5万
查看次数

ASP.Net Core 2.2 SignInManager '没有为方案'Identity.Application'注册登录身份验证处理程序

我在 Startup.cs 中有以下配置:

services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
    //options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o => {
    o.LoginPath = Routes.Urls.AdminAccountLogin;
    o.AccessDeniedPath = Routes.Urls.AdminAccountAccessdenied;
}).AddJwtBearer(configureOptions => {});
Run Code Online (Sandbox Code Playgroud)

当控制器登录操作调用时,应用程序抛出以下异常SignInManger.PasswordSignInAsync

发生异常:CLR/System.InvalidOperationException
抛出异常:System.Private.CoreLib.dll 中的“System.InvalidOperationException”:“没有为方案“Identity.Application”注册登录身份验证处理程序。注册的登录方案是: Cookies。你忘记调用 AddAuthentication().AddCookies("Identity.Application",...) 了吗?

在什么地方Identity.Application来的呢?

authentication cookies asp.net-core asp.net-core-identity

6
推荐指数
1
解决办法
3103
查看次数