Csharp/C Sharp by API/System.Security.Principal/WindowsIdentity — различия между версиями

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

Текущая версия на 12:10, 26 мая 2010

WindowsIdentity.AuthenticationType

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


WindowsIdentity.GetCurrent()

 
using System;
using System.Security.Principal;
class MainClass
{
    public static void Main (string[] args) 
    {
        
        WindowsIdentity identity = WindowsIdentity.GetCurrent();
    }
}


WindowsIdentity.Impersonate()

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


WindowsIdentity.IsAnonymous

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


WindowsIdentity.IsAuthenticated

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


WindowsIdentity.IsGuest

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


WindowsIdentity.IsSystem

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


WindowsIdentity.Name

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


WindowsIdentity.Token

 

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