VB.NETを使用してWindowsユーザーが属するドメインユーザーグループを検出する
-
05-07-2019 - |
質問
Dim currUser As String = Request.ServerVariables(" LOGON_USER")を使用するとDomain \ Usernameが返されることは知っていますが、そのユーザーがActive Directoryでどのグループにいるのかを知りたいです
解決
グループのリストが必要ですか?または、ユーザーが特定のグループのメンバーであるかどうかを確認しますか?
後者の場合、WindowsPrincipal.IsInRole()を使用して、ユーザーが特定のグループに属しているかどうかを確認できます。
http://msdn.microsoft.com/en-us/library /fs485fwh.aspx
たとえば、ユーザーが管理者であるかどうかを確認する場合は、次を使用できます。
If Page.User.IsInRole("BUILTIN\Administrators") Then
' Do something
End If
他のヒント
UserPrincipal.GetAuthorizationGroupsメソッドを使用できます。
imports System.DirectoryServices.AccountManagement
dim name as string = Request.ServerVariables("LOGON_USER")
dim user As UserPrincipal = UserPrincipal.FindByIdentity( new PrincipalContext( ContextType.Domain ), name)
dim groups As PrincipalSearchResult(Of Principal)= user.GetAuthorizationGroups()
所属していません StackOverflow