ASP.NET(C#)

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

步驟:

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



posted on 2005-04-18 16:19  battlerstar  阅读(728)  评论(2编辑  收藏  举报