Unable to resolve service for type IEmailSender while attempting to activate RegisterModel
I am using ASP.NET Core 3.0 and had similar issue. I added the following .AddDefaultUI() to my Startup.cs & it worked.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<IdentityUser, IdentityRole>()
.AddDefaultTokenProviders()
.AddDefaultUI()
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddControllersWithViews();
services.AddRazorPages().AddRazorRuntimeCompilation();
}
There're two ways to do that :
- remove the
services.AddDefaultTokenProviders()
in theConfigurureServices()
to disabletwo-factor authentication (2FA)
:// file: `Startup.cs` : services.AddDefaultIdentity<IdentityUser>() .AddEntityFrameworkStores<ApplicationDbContext>(); ///.AddDefaultTokenProviders(); /// remove this line
Add your own
IEmailSender
andISmsSender
implementation to DI contianer if you would like to enable2FA
// file: `Startup.cs` services.AddTransient<IEmailSender,YourEmailSender>(); services.AddTransient<IEmailSender,YourSmsSender>();
Edit:
Both should work.
Both should work for ASP.NET Core 2.1. However, as of ASP.NET Core 3.0, the first approach doesn't work any more.