基于角色的某些视图的用户权限
我正在使用 ASP.NET MVC 3。请原谅我的术语。我们为工作中的某些人员分配角色,然后使用 Windows 身份验证来确定用户具有哪些角色。假设角色是 RoleA、RoleB 和 RoleC。现在我得到了用户的角色列表。可以说 UserA 属于 RoleA 和 RoleB。我的一些观点需要经过验证,因为不是每个人都可以查看某些观点。假设 ViewA 只能由属于角色 RoleA 和 RoleB 的用户查看。我该怎么做?我需要调查什么?当不属于这些角色的用户尝试访问视图时,他/她应该被重定向到错误页面。
另外,我需要某种辅助方法来检查这些角色,并在我的视图中使用来隐藏/显示某些控件。在哪里使用这个功能最好?
任何示例代码/文章将不胜感激。
I am using ASP.NET MVC 3. Please excuse my terminology. We assign roles to certain people at work, then we use Windows authentication to determine what roles a user has. Lets say the roles are RoleA, RoleB and RoleC. So now I get a list of roles for a user. Lets says that UserA belongs to RoleA and RoleB. Some of my views need to be authenticated as not everyone can view certain views. Lets say that ViewA can only be viewed by users that belong to roles RoleA and RoleB. How would I do this? What would I need to look into? When a user that does not belong to these roles tries to access the views then he/she should be redirected to an error page.
Also, I need some sort of helper method to check these roles as well to be used in my views to hide/display certain controls. Where is the best place to use this?
Any sample code / articles would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想检查视图中的角色:
And if you want to check roles in the view: