使用AD的MVC3授权
是否可以使用 AD 授权/拒绝 MVC3 应用程序的用户?
我的应用程序目前使用 Windows 身份验证进行保护,但这意味着将用户添加到 Win2007 服务器上的组中。
我想更改这一点,以便用户根据其 AD 角色被允许/拒绝访问应用程序/和控制器操作/视图,这样他们要么自动登录(如 Windows 身份验证),要么被重定向到“被拒绝”页面。
非常感激地接受任何帮助...我发现的所有内容似乎都是基于 Windows 组或表单身份验证。
Is it possible to authorise/deny users of an MVC3 application using AD?
My app is secured using Windows authentication at the moment, but that means adding users to groups on the Win2007 server.
I'd like to change that so that users were allowed/denied access to the appliction/and controller actions/view based upon their AD roles instead, so they either auto-logged in (like Windows auth) or they get redirected to a "denied" page.
Any help very gratefully accepted...everything I find seems to be based upon Windows groups, or forms authentication.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 Roles 属性:
这是一个 教程 解释了这些步骤。
You could use the Roles property:
Here's a tutorial which explains the steps.
我正在为我的 Intranet 应用程序使用 AD 组。
然后只需将授权属性添加到我需要保护的控制器操作中:
在视图中,您可以使用 User.IsInRole 及其 AD/Windows 组的名称。
或者获取网络服务器从该用户看到的角色列表:
System.Web.Security.Roles.GetRolesForUser();
注意:我的服务器和客户端都在同一个域中。如果您需要针对 ActiveDirectory 对异地 Web 客户端执行相同的操作,则此方法将不起作用。
I'm using AD Groups for my intranet app.
then just added Authorization attributes to my controller actions that I needed to secure:
And in a view you can use
User.IsInRole
and the name of their AD/Windows group.Or get a list of the roles the webserver sees from that user:
System.Web.Security.Roles.GetRolesForUser();
Caveat: my server and my clients are all on the same domain. this won't work if you need to do the same for web clients off site against your ActiveDirectory.
只需使用 Asp.net 内置的会员提供程序框架即可。您会发现已经有一个 ActiveDirectoryMembershipProvider开箱即用,但您必须自己实现
RoleProvider
,因为成员资格可以在不同的网络中以不同的方式定义。Just use the Membership provider framework that comes built-in to Asp.net. You will find that there is already an ActiveDirectoryMembershipProvider out of the box, but you will have to implement the
RoleProvider
yourself, as membership can be defined different ways in different networks.