ASP.NET / VB.NET 检查(不同的)用户是否处于角色
我在我们公司的 Intranet 上有一个 ASP.NET 应用程序。还有一个时髦的安全要求。
我需要检查给定的用户名是否具有特定的角色。我无法使用,
Page.User.IsInRole("MyDomain\MyGroup")
因为
Page.User.Identity.Name
返回空字符串。由于该程序有一些可爱规范,我必须在 IIS 中启用匿名访问。似乎排除了任何 page.user.identity 的东西。
所以我确实找到了一种方法(至少)获取当前用户(来自 System.Environment.UserName),但我需要将其反弹到域组中以查看它们是否在其中。或者,更好的是,获取给定域内的用户列表,以便我可以检查自己。类似...-
Dim UserName as String
UserName = System.Environment.UserName
If User(UserName).IsInRole("MyDomain\MyGroup") Then
MyFunction = "Success"
End If
或者-
Dim GroupUsers as String()
GroupUsers = GetDomainUserNames("MyDomain\MyGroup")
有人有什么想法吗?
I have an ASP.NET application on our company's intranet. And a funky security requirement.
I need to check to see if a given username is in a certain role. I cannot use
Page.User.IsInRole("MyDomain\MyGroup")
because
Page.User.Identity.Name
Returns an empty string. Because of some lovely specifications for this program, I have to keep anonymous access enabled in IIS. Seems to rule out any page.user.identity stuff.
So I did find a way to (at least) get the current user (from System.Environment.UserName), but I need to bounce it against the domain group to see if they're in it. Or, better yet, get a list of users within a given domain so I can check myself. Something like...
Dim UserName as String
UserName = System.Environment.UserName
If User(UserName).IsInRole("MyDomain\MyGroup") Then
MyFunction = "Success"
End If
-OR -
Dim GroupUsers as String()
GroupUsers = GetDomainUserNames("MyDomain\MyGroup")
Anybody have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从 Roles 静态类调用 IsUserInRole。这是一个示例和一些参考资料。
链接: http://msdn.microsoft.com /en-us/library/system.web.security.roleprovider.isuserinrole.aspx
You can call IsUserInRole from the Roles static class. Here is a sample and some reference materials.
link: http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.isuserinrole.aspx