//獲取登陸頁輸入的域賬號、密碼 string domainIP = ""; //域IP string userAccount = ""; //域賬號 string Password = ""; //域賬號密碼 using (DirectoryEntry deUser = new Directory... ...
//獲取登陸頁輸入的域賬號、密碼 string domainIP = ""; //域IP string userAccount = ""; //域賬號 string Password = ""; //域賬號密碼 using (DirectoryEntry deUser = new DirectoryEntry(@"LDAP://" + domainIP, userAccount, Password)) { DirectorySearcher src = new DirectorySearcher(deUser); src.Filter = "(&(&(objectCategory=person)(objectClass=user))(sAMAccountName=" + userAccount + "))"; src.PropertiesToLoad.Add("cn"); src.SearchRoot = deUser; src.SearchScope = SearchScope.Subtree; SearchResult result = src.FindOne(); if (result != null)//驗證成功 { DirectoryEntry de = result.GetDirectoryEntry(); string userID = de.Username; #region 域賬號驗證通過後判斷是否用戶在本系統中 var existUser = new DAL.Maintain.UserOP().GetData(userID); if (existUser == null) { ViewBag.ErrorInfo = "提示:您未開通系統的許可權,請聯繫管理員。<br/>You have no access to the system, please contact the administrator!"; return View(); } #endregion FormsAuthentication.SetAuthCookie(userID, false); Session.Add("UserID", userID); Logger.DefaultLog.Info("登陸sessionUserID:" + Session["UserID"].ToString()); if (string.IsNullOrEmpty(ReturnUrl)) { return Redirect(Url.Action("Index", "Home")); } else { //... } } else { ViewBag.ErrorInfo = "提示:登錄失敗: 未知的用戶名或錯誤密碼。<br/>Account or Password is incorrect!"; return View(); } }