步驟:

1.     引用System.Security.Principal命名空间
       using System.Security.Principal; 

2.     代码
       WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent()); 

       wp.Identity.Name

另外:
   AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
   //Get the current principal and put it into a principal object.

   WindowsPrincipal MyPrincipal = (Thread.CurrentPrincipal as WindowsPrincipal);

   //Check the name and see if the user is authenticated.
           
   if(MyPrincipal.Identity.Name.Equals(@"XFRAME\Zeng.Zeng") && MyPrincipal.Identity.IsAuthenticated.Equals(true))
   {
    MessageBox.Show("Hello "+MyPrincipal.Identity.Name.ToString()+", you are authenticated!" );
   }
   else
   {
    MessageBox.Show("Go away! You are not authorized!");
   }



相关文章:

  • 2022-02-13
  • 2022-03-13
  • 2022-12-23
  • 2022-03-01
  • 2022-01-26
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
相关资源
相似解决方案