• asp.net 使用AD进行身份进行验证


    //在登录界面增加一个AD验证方法

        private static DirectoryEntry GetDirectoryObject(string userName,string userPwd)
        {
    
            DirectoryEntry entry = null;
            try
            {
    
                entry = new DirectoryEntry("LDAP://192.168.10.5:389/DC=ecera,DC=com,DC=tw", userName, userPwd, AuthenticationTypes.Secure);
            }
    
            catch (Exception ex)
            {
                throw ex;
            }
    
            return entry;
        } 

    //在登录按钮下如此使用

            DirectoryEntry entry = GetDirectoryObject(this.txtUserName.Value,this.txtUserPwd.Value);
            DirectorySearcher search = new DirectorySearcher(entry);
            search.Filter = "(SAMAccountName=" + this.txtUserName.Value+ ")";
            try
            {
    
                SearchResult result = search.FindOne();
    
                if (result != null)
                {
    
                    string userID = this.txtUserName.Value;
                    Session.Add("UserName", userID);
                    Session.Add("UserTrueName", UserInfoBll.Instance.GetUserName(userID));
                    Response.Redirect("~/SystemPage.htm");
    
                }
    
            }
    
            catch (Exception e1)
            {
    
                labMsg.Text =e1.Message.ToString() ;
    
            }  
    一切尽在淘婚网www.taohunla.com
  • 相关阅读:
    P2324 [SCOI2005]骑士精神
    Codeforces Round #574 (Div. 2) A~E Solution
    P4132 [BJOI2012]算不出的等式
    spring笔记(三)
    spring笔记(二)
    C3P0连接池参数解释
    spring笔记(一)
    hibernate笔记(四)
    hibernate笔记(三)
    hibernate笔记(二)
  • 原文地址:https://www.cnblogs.com/litao9026/p/2992902.html
Copyright © 2020-2023  润新知