用户访问权限或 Web 应用程序功能的权限模式或最佳实践
我必须在网络应用程序中实现用户访问权限或不同功能的权限。例如;如果用户无法查看报告,则不显示“报告”菜单,或者如果用户无法创建新员工,则不显示“新建”按钮。这些用户访问权限或许可将打开/关闭 UI 元素。我正在寻找模式或最佳实践来实现这一目标。
我正在考虑创建一个名为 bool UserHasPermission(Activity) 的函数。该函数将位于 UserSecurity 类内部。我将传递一些活动,例如“报告”以及真或假。如果为 true,那么我将执行 manuoption.visible = true 或反之亦然。
这是个好主意吗?唯一让我烦恼的是,我必须传递一个带有活动“报告”的字符串。
谢谢你的意见/建议,
奥尔多
I have to implement user access rights or permissions to different features in a web app. For example; if the user cannot view reports, do not show the Report menu, or if the user cannot create new employees, do not show the New button. These user access rights or permission would be turn on/off UI elements. I'm looking for patterns or best practices to accomplish this.
I was thinking on just creating a function called bool UserHasPermission(Activity). The function will be inside the UserSecurity Class. I'll pass some activity, like "Reports" and true or false. If true, then I will do manuoption.visible = true or the other way around.
Would this be a good idea? The only thing it bother me if that I'll have to pass a string with the activity "Reports".
Thank you your opinion/advice,
Aldo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要重新发明轮子,而是尝试重新打包
System.Web.Security
RoleProvider
(http://msdn.microsoft.com/en-us/library/system.web .security.roleprovider.aspx)和
ASP.NET 附带的
MembershipProvider
(http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.aspx) 类。然后,您可以利用预先编写和支持的接口,例如
IsInRole("blah");
教程:
http://www.15seconds.com/issue/050216.htm
Instead of reinventing the wheel, try and repackage the
System.Web.Security
RoleProvider
(http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.aspx)and
MembershipProvider
(http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.aspx) classes included with ASP.NET.You can then leverage the pre-written and supported interfaces e.g.
IsInRole("blah");
Tutorials:
http://www.15seconds.com/issue/050216.htm
http://www.devx.com/asp/Article/29256/0/page/3