Class1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:1k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Security.Principal;
  3. using System.Security.Permissions; using System.Threading;
  4. namespace Wrox.ProCSharp.Security
  5. {
  6.    class SecurityApp7
  7.    {
  8.       static void Main(string[] args)
  9.       {
  10.          AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
  11.          WindowsPrincipal principal = (WindowsPrincipal)Thread.CurrentPrincipal;
  12.          WindowsIdentity identity = (WindowsIdentity)principal.Identity;
  13.          Console.WriteLine("IdentityType:" + identity.ToString());
  14.          Console.WriteLine("Name:" + identity.Name);
  15.          Console.WriteLine("'Users'?:" + principal.IsInRole("BUILTIN\Users"));
  16.          Console.WriteLine("'Administrators'?:" + principal.IsInRole(WindowsBuiltInRole.Administrator));
  17.          Console.WriteLine("Authenticated:" + identity.IsAuthenticated);
  18.          Console.WriteLine("AuthType:" + identity.AuthenticationType);
  19.          Console.WriteLine("Anonymous?:" + identity.IsAnonymous);
  20.          Console.WriteLine("Token:" + identity.Token);
  21.       }
  22.    }
  23. }