设置自定义角色和角色基础模块访问权限

时间:2017-07-03 08:09:47

标签: c# asp.net-web-api model-view-controller

我想设置自定义角色和角色基础模块访问权限。并使用这个我想为控制器设置自定义授权。我不想用[授权(角色="经理,管理员和#34;)]设置修复(硬编码)角色名称,经理和管理员角色将是动态的。可能是高级经理或管理员而不是经理和管理员。

我想在Web API和MVC web中实现它。当用户登录时,系统将获得用户的角色,并且基于该角色,用户将能够访问modules.project。

我也附上了数据库和数据库脚本的截图。

i

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblModule](
    [ModuleId] [uniqueidentifier] NOT NULL,
    [ModuleName] [nvarchar](50) NOT NULL,
    [Status] [nvarchar](10) NOT NULL,
    [CreatedDate] [datetime] NOT NULL,
    [UpdatedDate] [datetime] NULL,
 CONSTRAINT [PK_tblModule] PRIMARY KEY CLUSTERED 
(
    [ModuleId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblRole](
    [RoleId] [uniqueidentifier] NOT NULL,
    [RoleName] [nvarchar](50) NOT NULL,
    [Status] [nvarchar](10) NOT NULL,
    [CreatedDate] [datetime] NOT NULL,
    [UpdatedDate] [datetime] NULL,
 CONSTRAINT [PK_tblRole] PRIMARY KEY CLUSTERED 
(
    [RoleId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblRoleModule](
    [RoleId] [uniqueidentifier] NOT NULL,
    [ModuleId] [uniqueidentifier] NOT NULL,
    [Status] [nvarchar](10) NOT NULL,
    [CreatedDate] [datetime] NOT NULL,
    [UpdatedDate] [datetime] NULL
) ON [PRIMARY]

GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblUser](
    [UserId] [uniqueidentifier] NOT NULL,
    [UserName] [nvarchar](50) NOT NULL,
    [Password] [nvarchar](50) NOT NULL,
    [FirstName] [nvarchar](20) NOT NULL,
    [LastName] [nvarchar](20) NOT NULL,
    [EmailId] [nvarchar](50) NULL,
    [Mobile] [nvarchar](15) NULL,
    [Status] [nvarchar](10) NOT NULL,
    [CreatedDate] [datetime] NOT NULL,
    [UpdatedDate] [datetime] NULL,
 CONSTRAINT [PK_tblUser] PRIMARY KEY CLUSTERED 
(
    [UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblUserRole](
    [UserId] [uniqueidentifier] NOT NULL,
    [RoleId] [uniqueidentifier] NOT NULL,
    [Status] [nvarchar](10) NOT NULL,
    [CreatedDate] [datetime] NOT NULL,
    [UpdatedDate] [datetime] NULL
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[tblRoleModule]  WITH CHECK ADD  CONSTRAINT [FK_tblRoleModule_tblModule] FOREIGN KEY([ModuleId])
REFERENCES [dbo].[tblModule] ([ModuleId])
GO
ALTER TABLE [dbo].[tblRoleModule] CHECK CONSTRAINT [FK_tblRoleModule_tblModule]
GO
ALTER TABLE [dbo].[tblRoleModule]  WITH CHECK ADD  CONSTRAINT [FK_tblRoleModule_tblRole] FOREIGN KEY([RoleId])
REFERENCES [dbo].[tblRole] ([RoleId])
GO
ALTER TABLE [dbo].[tblRoleModule] CHECK CONSTRAINT [FK_tblRoleModule_tblRole]
GO
ALTER TABLE [dbo].[tblUserRole]  WITH CHECK ADD  CONSTRAINT [FK_tblUserRole_tblRole] FOREIGN KEY([RoleId])
REFERENCES [dbo].[tblRole] ([RoleId])
GO
ALTER TABLE [dbo].[tblUserRole] CHECK CONSTRAINT [FK_tblUserRole_tblRole]
GO
ALTER TABLE [dbo].[tblUserRole]  WITH CHECK ADD  CONSTRAINT [FK_tblUserRole_tblUser] FOREIGN KEY([UserId])
REFERENCES [dbo].[tblUser] ([UserId])
GO
ALTER TABLE [dbo].[tblUserRole] CHECK CONSTRAINT [FK_tblUserRole_tblUser]
GO

0 个答案:

没有答案