授权MVC3-ASP.NET
我在我的应用程序中使用 Windows 身份验证。我正在使用 MVC3 –Asp.Net 和实体框架。我有一个菜单列表,它们是按钮。我正在使用站点地图来显示它们。我可以使用 Active Directory 中可用的角色隐藏或显示这些按钮。我有两个问题
1)如果我以基本用户身份登录(某些按钮对我来说不可见),这就是我想要的,但是如果我在中键入控制器/操作(此页面对我来说应该是不可见的)浏览器加载。
解决方案:
我正在检查用户及其角色作为操作中的第一行,如果我有权查看,那么我将显示否则重定向到其他页面。 从 Active Directory 对用户进行身份验证需要时间。
2)如果我以基本用户身份登录并尝试查看已为超级用户授权的操作,它仍然显示(当我手动输入控制器和操作名称时)
解决方案:
我正在检查用户及其角色作为操作中的第一行,如果我有权查看,那么我将显示其他内容重定向到另一个页面。 从 Active Directory 对用户进行身份验证需要时间。
说明:
我可以将授权属性与角色一起使用,并且我认为这仅适用于 ASP.NET 成员资格,并且因此,似乎不起作用,因为我的角色来自系统中的 Active Directory。
问题:
任何人都可以给我指出解决方案吗?我可以不检查每个视图的权限,而不能在全局中执行此操作。 asax 文件。如果我可以在用户登录时对其进行身份验证,那么我就不需要在其他视图中对他进行身份验证。
I am using windows authentication in my application. I am using MVC3 –Asp.Net with Entity framework. I have a list of menu, which are buttons. I am displaying them using them using sitemap. I am able to hide or show those buttons using the roles available in the Active directory. I have two issues
1) If I log in as a basic user(Some of the buttons are not visible to me) , which is what I want but if I am typing a Controller/Action(this Page should be invisible to me) in browser it loads up.
Solution:
I am checking the User and its role as the first line in the Action, if I am authorised to see that, then I am displaying otherwise redirecting to the other page.
It is taking time to authenticate a user from the Active Directory.
2) If I log in as a basic user and trying to see a Action been authorised for super user it still displays(when I manually type the Controller and Action Name)
Solution:
I am checking the User and its role as the first line in the Action, if I am authorised to see that, then I am displaying otherwise redirecting to the other page.
It is taking time to authenticate a user from the Active Directory.
Clarifications:
I can use Authorize attribute with roles and I am thinking this is only for ASP.NET Membership, and Hence Does not seems to work as my roles are coming from the Active Directory in the System.
Question:
Could any one point me to solution, where Instead of checking the permissions on each view can I not do that in Global. asax file. If I can authenticate the user once when he logged in , I don’t need to authenticate him for other views.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这两种情况下,我建议您编写自定义 RoleProvider Active Directory 角色提供程序。
然后,如果您正确设置了 MembershipProvider 和 RoleProvider,则 Authorize 属性应该可以工作。
为了避免通过 RoleProvider 在每个请求上检索用户的角色,您可以在会话中缓存该用户的角色。您可以在自定义 RoleProvider 中或使用自定义 Authorize 属性来执行此操作。
In both cases I would suggest you write custom RoleProvider Active Directory Role Provider.
Then if you have setup your MembershipProvider and RoleProvider correctly the Authorize attribute should work.
To avoid retrieving Roles of the user on each request through RoleProvider you can cache the roles of that user in the session. You can do that in the custom RoleProvider or by using custom Authorize attribute.