Update to 2.2 and Must comment out AddIdentity
After the following code has been done as instructed by the tutorial, the application fails to run.
public class IdentityHostingStartup : IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices((context, services) => {
services.AddDbContext<WebPWrecoverContext>(options =>
options.UseSqlServer(
context.Configuration.GetConnectionString("WebPWrecoverContextConnection")));
services.AddDefaultIdentity<IdentityUser>(config =>
{
config.SignIn.RequireConfirmedEmail = true;
})
.AddEntityFrameworkStores<WebPWrecoverContext>();
});
}
}
After about an hour of research, discovered that the same the startup.cs file. Please edit the docs to inform users to comment out this line of code.
//services.AddIdentity<IdentityUser, IdentityRole>()
// .AddEntityFrameworkStores<ApplicationDbContext>()
// .AddDefaultTokenProviders();
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: fe1bea60-d173-f6d2-3559-b147699e295a
- Version Independent ID: 98e7aacb-2a01-d581-9b03-bfef2893163e
- Content: Account confirmation and password recovery in ASP.NET Core
- Content Source: aspnetcore/security/authentication/accconfirm.md
- Product: aspnet-core
- GitHub Login: @Rick-Anderson
- Microsoft Alias: riande
I followed Kool-Koder 's advice and commented out the three lines in the startup.cs files, but it still did not work. WebPWrecoverContext in the IdentityHostingStartup.cs file was being underlined red, so I tried adding namespaces to remove them. Finally I got the red line to go away by changing it to ApplicationDBcontext. I was able to compile it but got a runtime database connection error. So I changed WebPWrecoverContextConnection to Default connection and got everything to work.
public class IdentityHostingStartup : IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices((context, services) => {
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
context.Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(config =>
{
config.SignIn.RequireConfirmedEmail = true;
})
.AddEntityFrameworkStores<ApplicationDbContext>();
});
}
}
Finally I got the red line to go away by changing it to ApplicationDBcontext.
Yes. This is how my one looks like too. I don't think you can just copy wholesale from the tutorial if you are trying to follow it and copy to another project at the same time. However, I believe the main purpose is it inform users of potential conflict in the startup.cs file, which wasn't made known in the docs.
{
public class IdentityHostingStartup : IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices((context, services) => {
services.AddDefaultIdentity<IdentityUser>(config =>
{
config.SignIn.RequireConfirmedEmail = true;
})
.AddEntityFrameworkStores<ApplicationDbContext>();
});
}
}
}
Thanks for contacting us. closed
I believe this isn't a question but more on a request to make the documentation clearer to warn people that potentially they may have this line of code somewhere in their project, in my case startup.cs which may throw up some errors.
//services.AddIdentity<IdentityUser, IdentityRole>()
// .AddEntityFrameworkStores<ApplicationDbContext>()
// .AddDefaultTokenProviders();