出现错误“ASP.Net 6 没有类型为'Microsoft.AspNetCore.Identity.UserManager'的服务。”通常是由于引用或配置问题引起的。以下是解决此问题的一些可能方法:
请注意,将x.x.x
替换为您想要使用的Identity版本。
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentity()
.AddDefaultTokenProviders()
.AddEntityFrameworkStores();
// 其他服务配置...
}
请注意,这假设您使用了默认的IdentityUser和IdentityRole。如果您有自定义的用户和角色实体,请相应地更改。
services.AddScoped>();
请注意,将CustomUser
替换为您自己的用户实体。
public class ApplicationDbContext : IdentityDbContext
{
// DbContext配置...
}
请注意,将CustomUser
和CustomRole
替换为您自己的用户和角色实体。
希望这些解决方法能够帮助您解决问题。如果问题仍然存在,请提供更多的代码和上下文信息,以便更好地帮助您解决问题。