Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheme already exists: Identity.Application #8223

Closed
ghost opened this issue Aug 22, 2018 · 10 comments · Fixed by #18061
Closed

Scheme already exists: Identity.Application #8223

ghost opened this issue Aug 22, 2018 · 10 comments · Fixed by #18061
Assignees
Projects
Milestone

Comments

@ghost
Copy link

ghost commented Aug 22, 2018

Have followed Create full identity UI source but am now receiving an error - “InvalidOperationException: Scheme already exists: Identity.Application” - when running solution. Startup.cs below;


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@ghost
Copy link
Author

ghost commented Aug 22, 2018

Not sure if this is a bug, an issue with doc or just I've miss-understood, however believe I have solved my problem.

IdentityHostingStartup.cs contained;

services.AddDefaultIdentity<IdentityUser>() .AddEntityFrameworkStores<myProjectContext>();

have commented this out and it seems to be working so far.
Doc: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.1&tabs=visual-studio

@Rick-Anderson Rick-Anderson added this to the Backlog milestone Aug 23, 2018
@Rick-Anderson Rick-Anderson added the Pri3 Priority 3 label Aug 23, 2018
@jimgit
Copy link

jimgit commented Oct 15, 2018

How do you configure the RequiredConfirmEmail and RequiredConfirmedPhoneNumber when this service code is commented out?

@simeyla
Copy link

simeyla commented Dec 2, 2018

@jimgit I think what he was saying was he had BOTH services.AddDefaultIdentity and services.AddIdentity defined in the same startup file.

Well that's what I had :-)

@a-z-hub
Copy link

a-z-hub commented Dec 31, 2018

In my case I had AddDefaultIdentity in Startup and IdentityHostingStartup
I think problem in scaffolding. I created project and after that I scaffold Identity and had 2 registration AddDefaultIdentity

@Rick-Anderson
Copy link
Contributor

Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments.

@sturlath
Copy link
Contributor

For others.

I store my context in another project (which is probably the reason it did not get populated in the drop down for creating the identity).

So I removed the following line from IdentityHostingStartup.cs

 services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<CreatedContext>();

and updated the Startup.cs file with

services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<CreatedContext>();

I did´t notice right away that the CreatedContext derived from IdentityDbConext

 public class CreatedContext : IdentityDbContext<IdentityUser>

@Lokesh-Eisen
Copy link

i have a similar issue but If i comment out that line that creates the identity I get no identy created but if I keep it I create 2 . I don't understand how this is possible. here is my startup.cs

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApp1.Data;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace WebApp1
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(
                    Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity<IdentityUser, IdentityRole>()
       // services.AddDefaultIdentity<IdentityUser>()
            .AddEntityFrameworkStores<WebApp1.Models.WebApp1Context>()
            .AddDefaultTokenProviders();


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseMvc();
        }
    }
}

@Hamid-Najafi
Copy link

Hamid-Najafi commented Jul 1, 2019

I think its scoffoling problem that add these line in IdentityHostingStartup.cs without checking services
please check ! @Rick-Anderson
run this :

dotnet new mvc -o MvcAuth -au Individual
code -r MvcAuth
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet aspnet-codegenerator identity -dc MyWeb.Data.ApplicationDbContext

now you have the problem

@meyer315
Copy link

meyer315 commented Aug 7, 2019

Sturlath, this worked for me as well...does anyone know if there will be any issues if

services.AddDefaultIdentity()
.AddEntityFrameworkStores();

are removed from the IdentityHostingStartup.cs file or is this required in a different way?

@asynts
Copy link

asynts commented Feb 16, 2020

For reference, I had the same issue when using services.AddDefaultIdentity() with services.AddAuthentication().AddIdentityCookies().

@Rick-Anderson Rick-Anderson removed the Pri3 Priority 3 label Apr 30, 2020
@Rick-Anderson Rick-Anderson reopened this Apr 30, 2020
@Rick-Anderson Rick-Anderson self-assigned this Apr 30, 2020
@Rick-Anderson Rick-Anderson added this to To do in April 2020 via automation Apr 30, 2020
April 2020 automation moved this from To do to Done Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
April 2020
  
Done
Development

Successfully merging a pull request may close this issue.

9 participants