Csharp/C Sharp by API/System.Security.Principal/WindowsIdentity

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

WindowsIdentity.AuthenticationType

<source lang="csharp"> 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);
 }

}

 </source>


WindowsIdentity.GetCurrent()

<source lang="csharp"> using System; using System.Security.Principal; class MainClass {

   public static void Main (string[] args) 
   {
       
       WindowsIdentity identity = WindowsIdentity.GetCurrent();
   }

}

 </source>


WindowsIdentity.Impersonate()

<source lang="csharp"> using System; using System.Collections.Generic; using System.IO; using System.IO.IsolatedStorage; using System.Net; using System.Net.Sockets; using System.Reflection; using System.Security; using System.Security.AccessControl; using System.Security.Policy; using System.Security.Permissions; using System.Security.Principal; using System.Text; public class MainClass {

   public static void Main()
   {
       WindowsIdentity identity = WindowsIdentity.GetCurrent();
       WindowsImpersonationContext context = identity.Impersonate();
       context.Undo();
   }

}

 </source>


WindowsIdentity.IsAnonymous

<source lang="csharp"> 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);
 }

}

 </source>


WindowsIdentity.IsAuthenticated

<source lang="csharp"> 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);
 }

}

 </source>


WindowsIdentity.IsGuest

<source lang="csharp"> 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);
 }

}

 </source>


WindowsIdentity.IsSystem

<source lang="csharp"> 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);
 }

}

 </source>


WindowsIdentity.Name

<source lang="csharp"> 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);
 }

}

 </source>


WindowsIdentity.Token

<source lang="csharp">

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);
 }

}

 </source>