当前位置:编程学习 > C#/ASP.NET >>

请教C#访问活动目录的代码问题

    public partial class Page1 : Page
    {
        public Page1()
        {
            InitializeComponent();
        }

        public static void GetAllOU()
        {
            try
            {
                Page3 pg = new Page3();
                DirectoryEntry entry = new DirectoryEntry("LDAP://ou=siso,dc=sipiso,dc=com,dc=cn", "sipiso\administrator", "Password", AuthenticationTypes.None);
                DirectorySearcher mySearcher = new DirectorySearcher(entry);
                mySearcher.Filter = ("(objectClass=organizationalUnit)");
                foreach (SearchResult resEnt in mySearcher.FindAll())
                {
                    pg.textBox1.Text = pg.textBox1.Text + resEnt.GetDirectoryEntry().Name.ToString() + "\t" + resEnt.GetDirectoryEntry().Name.ToString();
                }
            }
            catch(SecurityException ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            GetAllOU();
        }

这是一个WPF浏览器应用程序,运行至GetAllOU()是报出异常,具体如图所示。
--------------------编程问答-------------------- --------------------编程问答-------------------- 看不到图,发不上来的话就粘错误提示吧 --------------------编程问答-------------------- mySearcher.Filter = "(objectClass=organizationalUnit)";
  foreach (SearchResult resEnt in mySearcher.FindAll())
  {
  ResultPropertyCollection PropColl=resEnt.Properties;
  
  pg.textBox1.Text=PropColl["Name"][0].ToString();
  } --------------------编程问答-------------------- 错误提示:
请求“System.DirectoryServices.DirectoryServicesPermission, System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”类型的权限已失败。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,