我想讓我的項目中的用戶名和密碼,以及用戶的其它信息與active directory中的一致或者說是共用,我該如何實現??

解决方案 »

  1.   

    这里有详细的操作ad的方法,要取什么信息就取什么
    http://blog.csdn.net/xuandhu/archive/2005/03/16/320643.aspx
      

  2.   

    是用於cs中的??有沒有BS中的??
      

  3.   

    那是个类,在cs中可以用,在bs中也可以用,你甚至可以把这个类编译成dll,到哪都可以用
    bs和cs有区别吗?
      

  4.   

    我把这个类编译成了dll
    我放在我的项目中用了,bs,cs一样用
    嘿嘿
      

  5.   

    問下,我在page_load中加了一句Helper.ADHelper.Login("xwgang","trio");
    但調用時在public static DirectoryEntry GetDirectoryEntry(string commonName)
            {
                DirectoryEntry de = GetDirectoryObject();
                DirectorySearcher deSearch = new DirectorySearcher(de);
                deSearch.Filter = "(&(&(objectCategory=person)(objectClass=user))(cn=" + commonName + ")";
                deSearch.SearchScope = SearchScope.Subtree;
                try
                {
                    SearchResult result = deSearch.FindOne();                de = new DirectoryEntry(result.Path);
                    return de;
                }
                catch
                {
                    return null;
                }
            }
    每次都是取到的null,為什麼?
      

  6.   

    protected void Page_Load(object sender, EventArgs e)
        {
            lblMsg.Text = "";
            string domainName = "sz.co.jp";
            string groupName = "Domain Users";
            string dirmemName = "";
            try
            {            System.DirectoryServices.DirectoryEntry group = new System.DirectoryServices.DirectoryEntry("WinNT://" + domainName + "/" + groupName + ",group");            dirmemName = System.Environment.UserName;
                string FilterStr = "(sAMAccountname=" + dirmemName + ")";
                System.DirectoryServices.DirectorySearcher FindMe = new System.DirectoryServices.DirectorySearcher(domainName);
                FindMe.Filter = FilterStr;
                System.DirectoryServices.SearchResult FindRes = FindMe.FindOne();
                System.DirectoryServices.DirectoryEntry MyUser = FindRes.GetDirectoryEntry();
                string OUPath = MyUser.Parent.Path;
                System.DirectoryServices.DirectoryEntry myds = new System.DirectoryServices.DirectoryEntry(OUPath, "Administrator", "admin");
                foreach (System.DirectoryServices.DirectoryEntry tempEntry in myds.Children)
                {                
                    if (tempEntry.SchemaClassName.ToString() == "user" && tempEntry.Properties["sAMAccountName"].Value.ToString().ToLower() == dirmemName)
                    {
                        txtNO.Text = tempEntry.Properties["description"][0].ToString();
                        string temp = tempEntry.Properties["distinguishedName"][0].ToString();
                        string[] a = temp.Split(',');
                        txtDep.Text = a[1].Substring(3).ToString();
                        txtName.Text = a[0].Substring(3).ToString();                    
                    }
                }            
            }
            catch (Exception)
            {
                lblMsg.Text = "そのユーザーは見つけません";
                btnOK.Enabled = false;
            }
        }   很早以前写的,没写注释自己都看不大懂了,跟据登录计算机的用户名,从AD里提取该用户的信息,并显示。
      

  7.   

    你的问题可能在域的设置问题
            /// 
            /// 登录密码
            /// 
            private static string ADPassword = "DAFSDF";        /// 
            /// LDAP绑定路径
            /// 
            private static string ADPath = "LDAP://ad.com";        /// 
            /// 登录帐号
            /// 
            private static string ADUser = "asdgadsg";        /// 
            /// 域名
            /// 
            private static string DomainName = "AD";        /// 
            /// 扮演类实例
            /// 
            private static IdentityImpersonation impersonate = new IdentityImpersonation(ADUser, ADPassword, DomainName);        /// 
            /// LDAP 地址
            /// 
            private static string LDAPDomain = "DC=ad,DC=com";
    把机器加入域是ad.com的话 那LDAPDomain就设置成DC=ad,DC=com
    如果是ad.com.cn的话就是DC=ad,DC=com,DC=cn
    ADPath 就是LDAP://ad.com或LDAP://ad.com.cn
    域名就是DomainName,登陆的时候选择本机还是域名,就是用那个域名
    用户名和密码的话,最好用权限比较大的
      

  8.   

    我的有關參數設定值
            Helper.ADHelper.DomainName = "trio";    /// 域名
            Helper.ADHelper.LDAPDomain = "DC=trio,DC=com";   /// LDAP 地址
            Helper.ADHelper.ADPath = "LDAP://DC=trio,DC=com";  /// LDAP绑定路径
            Helper.ADHelper.ADUser = "xwgang";   /// 登录帐号
            Helper.ADHelper.ADPassword = "triotrio";     /// 登录密码
      

  9.   

    那位能不能幫我栓查下上面的參數有沒有問題,我的域為trio.com,用戶名xwgang,密碼triotrio
      

  10.   

    建議做法,去掉try, catch de換成 DirectoryEntry(path, userName, passWord)deSearch.Filter = "(&(&(objectCategory=person)(objectClass=user))(cn=" + commonName + ")"; 
    換成
    (&(objectCategory=person)(objectClass=user)(cn=*" + commonName + "*))
      

  11.   

    moldau 所說的修改可以,但我不明白原因,那位能幫我說明下嗎??