简体   繁体   English

ASP.NET MVC4中的角色和安全性

[英]Roles and Security in ASP.NET MVC4

Can anyone tell me the best way to implement Roles and security in ASP.NET MVC4 app. 谁能告诉我在ASP.NET MVC4应用程序中实现角色和安全性的最佳方法。

I am working on a MVC project and I want to implement the roles and security in that project. 我正在做一个MVC项目,我想在该项目中实现角色和安全性。 I have roles defined which I am getting from the database.But I dont know how to use those roles in my project. 我已经定义了从数据库中获取的角色,但是我不知道如何在我的项目中使用这些角色。 How can I make a connection(in webconfig or something) from which I can declare the roles on the Action method so that only users with those roles can only access that method. 如何建立连接(在webconfig或其他方式中),可以从该连接中声明Action方法上的角色,以便只有具有这些角色的用户才能访问该方法。

Like I have some roles : Read,Edit,Update ..I want only users with read role to only perform read operation and other operations respectively depending on roles. 就像我有一些角色: 读取,编辑,更新 ..我只希望具有读取角色的用户仅根据角色分别执行读取操作和其他操作。

I know this is a very broad question.but I just want to know the best way using which I can implement the roles and security in my application. 我知道这是一个非常广泛的问题。但是我只想知道在应用程序中实现角色和安全性的最佳方法。

What will be the step by step process: 逐步过程将是什么:

Do I need to make some connection in the webconfig so that the dataannotation with the role defined work or something.. 我是否需要在webconfig中建立一些连接,以便具有角色定义的数据注释起作用。

Plz help me guys. 请帮我。 Thanks. 谢谢。

Which authentication mode are you using? 您使用哪种身份验证模式? Forms authentication has option User.IsInRole but for that to work, you need to have Forms Authentication in place. 表单身份验证具有选项User.IsInRole,但要使其正常工作,您需要具有Forms Authentication User.IsInRole MSDN User.IsInRole MSDN

What you can do is create different views for Details, Insert/Update, Delete. 您可以做的是create different views for Details, Insert/Update, Delete. Then, on each controller, you just allow the users with your desired roles. 然后,在每个控制器上,您只允许具有所需角色的用户使用。

I think what you actually needed is RBAC. 我认为您真正需要的是RBAC。

User has one or more roles, and there are many functions for each role. 用户具有一个或多个角色,每个角色有许多功能。

User & Role, One to Many or Many to Many 用户和角色,一对多或多对多
Role & Function, Many to Many 角色与功能,多对多

http://en.wikipedia.org/wiki/Role-based_access_control http://en.wikipedia.org/wiki/基于角色的访问控制

Add an AuthorizeAttribute(eg: MyAuthorize) class. 添加一个AuthorizeAttribute(例如:MyAuthorize)类。

[MyAuthorize("Admin-User-Add")]
public ActionResult Add(){}

"Admin-User-Add" is the unique key of the function of "Add user action". “管理员用户添加”是“添加用户操作”功能的唯一键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM