asp.net – 为什么这违反了类型约束?
发布时间:2020-12-16 00:48:16 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试自定义ASP.NET身份3,以便它使用整数键: public class ApplicationUserLogin : IdentityUserLoginint { }public class ApplicationUserRole : IdentityUserRoleint { }public class ApplicationUserClaim : IdentityUserClaimint { }public seale
我正在尝试自定义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(); 宣布关键类型似乎超越了崩溃 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – HTML敏捷包删除break标签关闭
- asp.net-mvc – ASP.NET MVC WebApi:没有为此对象定义的无
- asp.net-web-api – MVC Core ZipArchive无效
- 从ASP.NET SQL memership DB中删除已失效/缺少应用程序的引
- asp.net-mvc – 处理CORS预检请求到ASP.NET MVC操作
- asp.net – WebAPI Empty 500错误
- asp.net-mvc – 我如何moq aingleingleResult?我是不是该?
- asp.net – 单声道随机CS0006编译错误w / fastcgi-mono-ser
- ASP.NET中TextBox控件设立ReadOnly="true"后台取不
- asp.net-mvc-2 – 如何在ASP.NET MVC2中为Html.LabelFor()添
推荐文章
站长推荐
- 通过扩展让ASP.NET Web API支持JSONP
- asp.net-mvc – 如何单元测试应用了[Authorize]属
- ASP.NET处理程序未在IIS7上运行
- 如何下载特定版本的ASP.NET MVC 5源代码
- asp.net – Objectdatasource和Gridview:排序,分
- 验证 – 关于构建asp.net mvc应用程序的建议
- asp.net-mvc – AOP vs MVC FilterAttributes vs
- asp.net-mvc – ASP.NET MVC帖子模型的示例?
- 为什么工作线程使我的ASP.NET生成器在睡眠期间遇
- asp.net-mvc – 使用数字属性的MVC3 DataAnnotat
热点阅读