asp.net – 为什么这违反了类型约束?
发布时间:2020-05-27 23:16:42 所属栏目:asp.Net 来源:互联网
导读:我正在尝试自定义ASP.NET身份3,以便它使用整数键: public class ApplicationUserLogin : IdentityUserLoginint { }public class ApplicationUserRole : IdentityUserRoleint { }public class ApplicationUserClaim : IdentityUse
|
我正在尝试自定义ASP.NET身份3,以便它使用整数键: public class ApplicationUserLogin : IdentityUserLogin<int> { }
public class ApplicationUserRole : IdentityUserRole<int> { }
public class ApplicationUserClaim : IdentityUserClaim<int> { }
public sealed class ApplicationRole : IdentityRole<int>
{
public ApplicationRole() { }
public ApplicationRole(string name) { Name = name; }
}
public class ApplicationUserStore : UserStore<ApplicationUser,ApplicationRole,ApplicationDbContext,int>
{
public ApplicationUserStore(ApplicationDbContext context) : base(context) { }
}
public class ApplicationRoleStore : RoleStore<ApplicationRole,int>
{
public ApplicationRoleStore(ApplicationDbContext context) : base(context) { }
}
public class ApplicationUser : IdentityUser<int>
{
}
public sealed class ApplicationDbContext : IdentityDbContext<ApplicationUser,int>
{
private static bool _created;
public ApplicationDbContext()
{
// Create the database and schema if it doesn't exist
if (!_created) {
Database.AsRelational().Create();
Database.AsRelational().CreateTables();
_created = true;
}
}
}
这可以编译好,但是会抛出一个运行时错误:
UserStore的签名是: public class UserStore<TUser,TKey> where TUser : Microsoft.AspNet.Identity.EntityFramework.IdentityUser<TKey> where TRole : Microsoft.AspNet.Identity.EntityFramework.IdentityRole<TKey> where TContext : Microsoft.Data.Entity.DbContext where TKey : System.IEquatable<TKey> ApplicationUser正是一个IdentityUser< int>。这不是它在寻找什么吗? 解决方法进入这个问题。这是在startup.cs文件中崩溃。变 services.AddIdentity<ApplicationUser,ApplicationIdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
至 services.AddIdentity<ApplicationUser,ApplicationIdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext,int>()
.AddDefaultTokenProviders();
宣布关键类型似乎超越了崩溃 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- .net – 为什么在单击按钮时,SelectedIndexChanged会触发Dr
- 将ASP.Net MVC的单页添加到现有的Web窗体应用程序中?
- asp.net-mvc – Server 2008 R2上的MVC – 如何?
- ef-code-first – 如何使用LocalDB和EF,而不使用迁移
- asp.net – 使用GhostScript将PDF转换为服务器上的图像集合
- asp.net – 我想列出我的下拉列表中的所有国家/地区,我在哪
- SqlServer如何给表添加新的字段以及字段注释
- asp.net-mvc – 尝试使用TeamCity构建asp.net mvc Web应用程
- asp.net-mvc – ASP.NET MVC 3列表到IEnumerable
- asp.net-mvc – ASP.NET MVC架构如何适应传统的多层架构
推荐文章
站长推荐
- asp.net-mvc-3 – MVC 3使用RenderPage更改视图中
- ASP.NET MVC身份验证Cookie未被检索
- 如何在ASP.NET中设置TextBox中的对齐中心?
- asp.net-mvc – 在ASP.Net MVC中使用System.Guid
- 强制ASP.NET GridView的寻呼机显示
- asp.net – asp文本框限制字符数?
- 在ASP.NET Core 2.0 / Angular模板应用程序上发布
- asp.net-membership – 如何在成员资格提供者上实
- 通过asp.net 4.0中的“EnableViewState”和“Vie
- asp.net – 如何将gridview列绑定到子类值?
热点阅读
