[英].NET 6 Identity Customization - Error: There is no implicit reference conversion from ApplicationUser to IdentityUser<string>
I have customized all .NET 6 Identity model classes.我已经定制了所有 .NET 6 Identity model 类。 My setup was working just fine for over a year.
我的设置工作了一年多。 I updated to the latest .NET core identity libraries (6.0.7) and ran a new DB-Scaffold today, and all of a sudden, I'm getting the following error for ApplicationUser (plus the same error for the remainder of the custom Identity classes):
我更新到最新的 .NET 核心身份库(6.0.7)并今天运行了一个新的 DB-Scaffold,突然之间,我收到了 ApplicationUser 的以下错误(加上自定义身份的其余部分的相同错误类):
CS0311 The type 'ApplicationUser' cannot be used as type parameter 'TUser' in the generic type or method 'IdentityDbContext<TUser, TRole, TKey, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken>'.
CS0311 类型“ApplicationUser”不能用作泛型类型或方法“IdentityDbContext<TUser, TRole, TKey, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken>”中的类型参数“TUser”。 There is no implicit reference conversion from 'ApplicationUser' to 'Microsoft.AspNetCore.Identity.IdentityUser'
没有从“ApplicationUser”到“Microsoft.AspNetCore.Identity.IdentityUser”的隐式引用转换
I've got the EF database context configured as follows:我已将 EF 数据库上下文配置如下:
public partial class DatabaseContext: IdentityDbContext<ApplicationUser, ApplicationRole, string, ApplicationUserClaim, ApplicationUserRole, ApplicationUserLogin, ApplicationRoleClaim, ApplicationUserToken>
My Identity classes are as follows:我的身份类如下:
public partial class ApplicationUser: IdentityUser<string>
public partial class ApplicationRole: IdentityRole<string>
public partial class ApplicationUserClaim: IdentityUserClaim<string>
public partial class ApplicationUserRole: IdentityUserRole<string>
public partial class ApplicationUserLogin: IdentityUserLogin<string>
public partial class ApplicationRoleClaim: IdentityRoleClaim<string>
public partial class ApplicationUserToken: IdentityUserToken<string>
This approach seems to be lined up with what Microsoft recommends here: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/customize-identity-model?view=aspnetcore-6.0这种方法似乎与微软在这里推荐的一致: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/customize-identity-model?view=aspnetcore-6.0
I've tried everything I can think of but the errors are still coming up (tried changing over to a Guid instead of a string, for example).我已经尝试了我能想到的所有方法,但错误仍然出现(例如,尝试转换为 Guid 而不是字符串)。 I'm at a loss and hoping someone might be able to give me some advice on how to fix these errors?
我很茫然,希望有人能给我一些关于如何解决这些错误的建议?
This was due to the fact that I was still configured for the .NET 5 way of using Identity.这是因为我仍然为 .NET 5 使用身份的方式进行了配置。 I created a new .NET 6 MVC project and migrated everything over to it, and that fixed the problem.
我创建了一个新的 .NET 6 MVC 项目并将所有内容迁移到它,这解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.