Get the current identity : WindowsIdentity « Security « C# / CSharp Tutorial






using System;
using System.Security.Principal;


class MainClass
{
  public static void Main() 
  {
    WindowsIdentity wi = WindowsIdentity.GetCurrent();

    Console.WriteLine("Identity information:");
    Console.WriteLine("  Authentication Type: {0}",wi.AuthenticationType);
    Console.WriteLine("  Is Anonymous: {0}", wi.IsAnonymous);
    Console.WriteLine("  Is Authenticated: {0}", wi.IsAuthenticated);
    Console.WriteLine("  Is Guest: {0}", wi.IsGuest);
    Console.WriteLine("  Is System: {0}", wi.IsSystem);
    Console.WriteLine("  Name: {0}", wi.Name);
    Console.WriteLine("  Token: {0}", wi.Token);
  }
}
Identity information:
  Authentication Type: NTLM
  Is Anonymous: False
  Is Authenticated: True
  Is Guest: False
  Is System: False
  Name: JAVA2S\Joe
  Token: 1800








35.1.WindowsIdentity
35.1.1.Obtain a WindowsIdentity object representing the currently logged on Windows user
35.1.2.Get the current identity
35.1.3.Get the current identity and its associated principal
35.1.4.Determining group identity: WindowsBuiltInRole.PowerUser
35.1.5.Iterate through the group names to see if the current user is a member of each one
35.1.6.Impersonation
35.1.7.Get current principal identity name