Asp.net WebForms启用角色 [英] Asp.net WebForms Enable Roles
问题描述
我已经使用ASP.NET WebForms通过Visual Studio 2017创建了一个网页.
I've created a Webpage via Visual Studio 2017 using ASP.NET WebForms.
我正在使用内置的用户管理并创建了一些用户.
I'm using the build-in User Management and created some users.
现在我要使用角色功能.
Now I want to use the Role-Function.
首先我启用了角色管理器,但是随后出现一个新错误 找不到存储过程'dbo.aspnet_CheckSchemaVersion"
First I've enabled the roleManager, but then I get a new error "Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion"
我尝试使用aspnet_regsql.exe向数据库添加必要的部分,但是现在我的数据库中有两种表:AspNetUsers和aspnet_Users.
I've tried to use the aspnet_regsql.exe to add the necessary parts to the database, but now I have two kind of tables in my database: AspNetUsers and aspnet_Users.
要使用旧的AspNet-Schematic启用角色,我该怎么做?
What Do I have to do, to enable roles with the old AspNet-Schematic?
推荐答案
使用VisualStudio使用Microsoft.AspNet.Identity创建的标准WebForms,因此也创建数据库以使用Microsoft.AspNet.Identity的示意图.
Standard-WebForms created with VisualStudio using Microsoft.AspNet.Identity so also the Database is created to use the Schematic of Microsoft.AspNet.Identity.
因此,您必须使用RoleManager来添加角色:
Therefore you have to use the RoleManager to add Roles:
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具有其自己的原理图,不适用于Microsoft.AspNet.Identity
System.Web.Security has it's own Schematic and does not work with Microsoft.AspNet.Identity
这篇关于Asp.net WebForms启用角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!