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

AD 域验证

Posted on 2004-07-22 22:35  LeeCheng  阅读(642)  评论(0编辑  收藏  举报

   this.Label2.Text = user.IsInRole(@"Wicresoft\").ToString();
   //Label1.Text = HttpContext.Current.User.Identity.IsAuthenticated.ToString() +"       "+ User.Identity.Name;
   Label1.Text = GetAllOU(User.Identity.Name);
   // Put user code to initialize the page here
  }

  public string GetAllOU(string strLogin )
  {
   string str = "";
   // Parse the string to check if domain name is present.
   int idx = strLogin.IndexOf('\\');
   if (idx == -1)
   {
    idx = strLogin.IndexOf('@');
   }

   string strDomain;
   string strName;

   if (idx != -1)
   {
    strDomain = strLogin.Substring(0, idx);
    strName = strLogin.Substring(idx+1);
   }
   else
   {
    strDomain = Environment.MachineName;
    strName = strLogin;
   }

   DirectoryEntry obDirEntry = null;
   try
   {
    obDirEntry = new DirectoryEntry("WinNT://" + strDomain + "/" + strName);
    System.DirectoryServices.PropertyCollection  coll = obDirEntry.Properties;
    object obVal = coll["FullName"].Value;
    str = obVal.ToString();
   }
   catch (Exception ex)
   {
    str = "";
    Trace.Write(ex.Message);
   }
   return str;