AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Update to 2.2 and Must comment out AddIdentity

Open Kool-Koder opened this issue 7 years ago • 4 comments

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.

Kool-Koder avatar Dec 24 '18 14:12 Kool-Koder

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>();
        });
    }
}

krypticipher avatar Jan 07 '19 08:01 krypticipher

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>();
                
            });
        }
    }
}

Kool-Koder avatar Jan 07 '19 08:01 Kool-Koder

Thanks for contacting us. closed

Rick-Anderson avatar Jan 07 '19 20:01 Rick-Anderson

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();   

Kool-Koder avatar Jan 09 '19 17:01 Kool-Koder