I am using Active Directory to authenticate users for an intranet site. I would like to refine the users that are authenticated based on the group they are in in Active Directory. Can someone show me or point me to directions on how to find what groups a user is in in ASP.NET 4.0 (VB)?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- how to use special characters like '<'
- Request.PathInfo issues and XSS attacks
I realize this post is quite old but I thought I might update it with processes I am using. (ASP.Net 4.0, VB)
If using integrated windows security, on a domain.
Page.User.IsInRole("domain\GroupName")
will check to see if the authenticated user is a member of the specified group.If you would like to check another users group membership other than the authenticated user.
Two stage for checking multiple groups with the same user principal:
Single stage for checkin a single group:
NOTE:: The IsInRole method does work with nested groups. If you have a top level group with a sub group that is a member, and the user is a member of the sub group.
I think I have the ultimate function to get all AD groups of an user included nested groups without explicit recursion:
Imports System.Security.Principal
So just use GetGroups("userID"). Because this approach uses the SID of the user, no explicit LDAP call is done. If you use your own user name it will use the cached credentials and so this function is very fast.
The Try Catch is necessary because in large companyies the AD is so big that some SIDs are getting lost in space.
To just check if a user is member of a group including sub-groups just use:
I found this here.
For those who may be interested, this is how I ended up coding it: