Dan*_*ani 17 identity asp.net-identity .net-core asp.net-core
我正进入(状态
InvalidOperationException:没有注册类型'Microsoft.AspNetCore.Identity.SignInManager 1 [Authorization.IdentityModels.ApplicationUser]'的服务.
当我运行我的ApsCore MVC网站时.
这是我的代码中的段:
ConfigureServices:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole<Guid>>()
.AddEntityFrameworkStores<ApplicationDbContext, Guid>()
.AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)
配置:
app.UseIdentity();
Run Code Online (Sandbox Code Playgroud)
ApplicationDbContext.cs
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole<Guid>, Guid>
Run Code Online (Sandbox Code Playgroud)
ApplicationUser.cs
public class ApplicationUser : IdentityUser<Guid>
Run Code Online (Sandbox Code Playgroud)
如果你能帮助我,我会很高兴的.
Naz*_*lov 27
将我的Identity类移动到Guid并在此处找到解决方案后面临同样的问题:
您可能需要更改登录部分视图以使用新用户类型IdentityUser
在Views/Shared/_LoginPartial.cshtml中,我刚才改变了
@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
Run Code Online (Sandbox Code Playgroud)
至
@using Microsoft.AspNetCore.Identity
@inject SignInManager<MyUser> SignInManager
@inject UserManager<MyUser> UserManager
Run Code Online (Sandbox Code Playgroud)
这对我有用.
Mad*_*Dev 15
不确定你是否仍然看到这个问题,但是对于偶然发现这个问题的其他人来说,这里有一些帮助.
问题来自您的应用程序中需要在其构造函数中使用SignInManager的某个类,但在依赖项注入设置中没有与其关联的实现.
要在Startup类中修复ConfigureServices方法,请在服务中注册SignInManager类.例如:
services.AddScoped<SignInManager<ApplicationUser>, SignInManager<ApplicationUser>>();
AddIdentity扩展方法可能已更新,因为原始问题被要求添加此方法,但相同的错误类型将显示IoC容器无法解决的任何内容.
| 归档时间: |
|
| 查看次数: |
17228 次 |
| 最近记录: |