我已经使用 ASP.NET WebForms 通过 Visual Studio 2017 创建了一个网页。
我正在使用内置的用户管理并创建了一些用户。
现在我想使用角色函数。
首先,我启用了 roleManager,但随后出现新错误“找不到存储过程 'dbo.aspnet_CheckSchemaVersion”
我曾尝试使用 aspnet_regsql.exe 将必要的部分添加到数据库中,但现在我的数据库中有两种表:AspNetUsers 和 aspnet_Users。
我必须做什么才能使用旧的 AspNet-Schematic 启用角色?
使用 Microsoft.AspNet.Identity 使用 VisualStudio 创建的标准 WebForms,因此还创建了数据库以使用 Microsoft.AspNet.Identity 的原理图。
因此,您必须使用 RoleManager 添加角色:
string roleName = "role";
var roleManager = new RoleManager<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
if (!roleManager.RoleExists(roleName))
{
var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
role.Name = TextBoxRole.Text;
roleManager.Create(roleName);
}
System.Web.Security 有它自己的 Schematic 并且不适用于 Microsoft.AspNet.Identity
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句