The System.Security.Principal.WindowsPrincipal class in C# is a part of the .NET Framework that provides an easy and efficient way of determining the Windows identity of users currently running an application. This class is available in the System.Security.Principal namespace and enables you to check the current Windows user's role and group information.
Example 1: To check whether the current user is a member of the administrative group or not, use the following code:
// create a new WindowsPrincipal object WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
// check whether the current user is an administrator or not bool isAdmin = wp.IsInRole(WindowsBuiltInRole.Administrator);
Example 2: To get the groups to which the current user belongs, use the following code:
// create a new WindowsPrincipal object WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
// get the groups to which the current user belongs var groups = wp.GetGroups();
Package Library: System.Security.Principal.
C# (CSharp) System.Security.Principal WindowsPrincipal - 49 examples found. These are the top rated real world C# (CSharp) examples of System.Security.Principal.WindowsPrincipal extracted from open source projects. You can rate examples to help us improve the quality of examples.