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

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

Версия 15:31, 26 мая 2010

new WindowsPrincipal(WindowsIdentity wi)

using System;
using System.Security.Principal;

class MainClass
{
  public static void Main() 
  {
    WindowsIdentity wi = WindowsIdentity.GetCurrent();
    
    WindowsPrincipal prin = new WindowsPrincipal(wi);
    Console.WriteLine("Principal information:");
    Console.WriteLine("  Authentication Type: {0}", prin.Identity.AuthenticationType);
    Console.WriteLine("  Is authenticated: {0}", prin.Identity.IsAuthenticated);
    Console.WriteLine("  Name: {0}", prin.Identity.Name);
  }
}


WindowsPrincipal.IsInRole

using System;
using System.Security.Principal;
class MainClass
{
    public static void Main (string[] args) 
    {
        
        WindowsIdentity identity = WindowsIdentity.GetCurrent();
        WindowsPrincipal principal = new WindowsPrincipal(identity);
        
        foreach (string role in args) 
        {
            Console.WriteLine("Is {0} a member of {1}? = {2}", identity.Name, role, principal.IsInRole(role));
        }
    }
}