AddIdentity()失败"InvalidOperationException:方案已经存在:Identity.Application".

编程入门 行业动态 更新时间:2024-10-25 14:26:16
本文介绍了AddIdentity()失败"InvalidOperationException:方案已经存在:Identity.Application".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将Facebook登录名添加到我的.NET Core 2.1站点

I'm trying to add facebook login to my .NET Core 2.1 site

我正在关注 this ,指南以及更具体的此(用于Facebook登录)

I'm following this , guide and more specific, this (for facebook login)

将以下几行添加到startup.cs之后,在ConfigureServices-method之内

After have adding the lines below to startup.cs, inside ConfigureServices-method

public void ConfigureServices(IServiceCollection services) { ... services.AddIdentity<ApplicationUser, IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); ... }

运行应用程序时收到错误消息.没有这些行,它正常"工作.用户可以登录到Facebook并批准我的申请,然后我收到电子邮件,但没有收到.但是我猜用户信息不会被添加到我的数据库中

I get the error message, when I'm running the application. Without these lines it works "ok". The user can login to facebook and approve my application and I get email and what not. BUT I'm guessing the user information will not be added to my database

InvalidOperationException:方案已经存在:Identity.Application Microsoft.AspNetCore.Authentication.AuthenticationOptions.AddScheme(字符串 名称,操作configureBuilder)...

InvalidOperationException: Scheme already exists: Identity.Application Microsoft.AspNetCore.Authentication.AuthenticationOptions.AddScheme(string name, Action configureBuilder)...

代码超出了添加的行,并且不久(启动期间)后出现错误.我已经搜索了我的项目(从模板开始只是一个裸露的.NET Core 2.1 Web应用程序),但是看不到"AddIdentity"的任何其他用法.

The code goes past the added lines and the error appears after a short while (during startup). I have searched in my project (which is just a bare .NET Core 2.1 Web application, from template) and I cant see any other usages of "AddIdentity".

我确实找到了"AddDEfaultIdentity()",将该行注释掉了.但后来我得到了

I did find a "AddDEfaultIdentity()", commented that line out. but then I got

InvalidOperationException:没有针对该类型的服务 'Microsoft.AspNetCore.Identity.UserManager`1 [Microsoft.AspNetCore.Identity.IdentityUser]' 已注册. Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider提供者,类型serviceType)

InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered. Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)

推荐答案

我遇到了类似的问题.这对于使用.Net Core 3.0的人们可能更有用.深入研究后,我发现一旦您使用脚手架创建身份"区域.在Identity文件夹中创建了一个名为"IdentityHostingStartup.cs"的文件.

I had a similar issue. This might be more helpful for people using .Net Core 3.0. After digging around I found out that once you create an "Identity" area using scaffolding. A file called "IdentityHostingStartup.cs" is created inside the Identity folder.

在类中,将创建"AddDefaultIdentity"的另一个实例以及其他一些服务.

Inside the class, another instance of "AddDefaultIdentity" is created along with a few other services.

如果从"Startup.cs"中删除"addDefaultIdentity",则您的应用应启动.另外,如果收到空连接字符串错误.更新IdentityHostintgStartup.cs内部的连接字符串

If you remove the "addDefaultIdentity" from your "Startup.cs" your app should start. Also, If you are getting a null connection string error. Update the connection string inside of the IdentityHostintgStartup.cs

注意:删除两个addDefaultIdentities都可以.您只是不能在两个地方都拥有它.

Note: Deleting either of the addDefaultIdentities will work. You just can't have it in both locations.

希望这会有所帮助.

更多推荐

AddIdentity()失败"InvalidOperationException:方案已经存在:Identity.Application"

本文发布于:2023-11-05 06:13:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560116.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方案   quot   AddIdentity   InvalidOperationException   Application

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!