C# ASP.NET核心MVC-创建角色
我在一本书中(在学习C#的过程中)进行了介绍,这个MVC项目的安全控制器有以下几行代码C# ASP.NET核心MVC-创建角色,c#,asp.net-core,C#,Asp.net Core,我在一本书中(在学习C#的过程中)进行了介绍,这个MVC项目的安全控制器有以下几行代码 AppIdentityRole role = new AppIdentityRole(); role.Name = "Manager"; role.Description = "Can perform CRUD operations."; IdentityResult roleResult = roleManager.CreateAsync(role).Result;
AppIdentityRole role = new AppIdentityRole();
role.Name = "Manager";
role.Description = "Can perform CRUD operations.";
IdentityResult roleResult = roleManager.CreateAsync(role).Result;
在MS VS 2019通信中,它会抛出一个错误
错误CS1503参数1:无法从“EmployeeManager.MVC.Security.AppIdentityRole”转换为“EmployeeManager.MVC.Security.AppIdentityUser”EmployeeManager.MVC
它是第三章系统的一部分
我的理解是,代码试图在底层安全层和SQL数据库Northwind中创建一个新角色
非常感谢您的帮助。哪一行给出了该错误?你确定你以完全相同的方式复制到你自己的应用程序中吗?顺便说一句,该代码处理异步代码的方式不正确。如果一本书有那么明显的错误,你确定要用它来学习吗?谁知道它还能教你什么坏习惯……你能更新你的代码来看看roleManager的定义吗?谢谢Ziv提出这个问题——我在通过复制粘贴和老眼光定义roleManager时搞砸了,没有发现我的错误。梅森-谢谢你的投入,我在书中发现了一些错误,但通过修复它们,我学到了比原始材料更多的东西。