private string GetADUser(string gourp, string name) { string json = string.Empty; Yawei.Domain.Domain domain = new Yawei.Domain.Domain(); if (name.Trim() != "") { SearchResultCollection searchResultCollection = Yawei.Domain.Domain.ExecuteSearchResult(domain.GetDirectoryEntry(domain.DistinguishedName), "(&(objectCategory=person)(objectClass=user)(CN=*" + name + "*))", SearchScope.Subtree); json += "{"; json += "\"total\":" + searchResultCollection.Count.ToString() + ",\"rows\":["; for (int i = 0; i < searchResultCollection.Count; i++) { DomainUser user = domain.GetUser(searchResultCollection[i].GetDirectoryEntry().Guid.ToString()); json += "{\"UserGuid\":\"" + user.Guid.ToString() + "\",\"UserDN\":\"" + user.DN + "\",\"UserCN\":\"" + user.CN + "\",\"UserLoginName\":\"" + user.LoginName + "\",\"UserType\":\"AD\"}"; if (i + 1 < searchResultCollection.Count) { json += ","; } } json += "]}"; } else { using (DomainOU domainOU = domain.GetOU(gourp)) { SearchResultCollection searchResultCollection = Yawei.Domain.Domain.ExecuteSearchResult(domainOU, "(&(objectCategory=person)(objectClass=user))", SearchScope.OneLevel);;//Yawei.Domain.Domain.ExecuteSearchResult(domainOU, "(&(objectCategory=person)(objectClass=user))", SearchScope.OneLevel); json += "{"; json += "\"total\":" + searchResultCollection.Count.ToString() + ",\"rows\":["; for (int i = 0; i < searchResultCollection.Count; i++) { DomainUser user = domain.GetUser(searchResultCollection[i].GetDirectoryEntry().Guid.ToString()); json += "{\"UserGuid\":\"" + user.Guid.ToString() + "\",\"UserDN\":\"" + user.DN + "\",\"UserCN\":\"" + user.CN + "\",\"UserLoginName\":\"" + user.LoginName + "\",\"UserType\":\"AD\"}"; if (i + 1 < searchResultCollection.Count) { json += ","; } } json += "]}"; } } return(json); }
/// <summary> /// 初始化页面属性及操作。 /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { try { string userType = ConfigurationManager.AppSettings["SystemUser"]; switch (userType.ToUpper()) { case "AD": if (Request.Cookies["CurrentUserInfo"] == null) { TicketManager ticketManager = new TicketManager(); if (ticketManager.LoadTicket(ConfigurationManager.AppSettings["domain"])) { Yawei.Domain.Domain domain = new Yawei.Domain.Domain(); using (DomainUser domainUser = domain.GetUser(ticketManager.ADGuid)) { CurrentUser.SetCookieUserInfo(ticketManager.ADGuid, domainUser.CN, domainUser.DN, ticketManager.Userid); } GetUser(ticketManager.ADGuid); SetOnlinUser(); } //else // Response.Redirect(AppSupport.AppPath + "/SystemOption/lock.html"); } else { var guid = Request.Cookies["CurrentUserInfo"].Values["CurrentUserGuid"]; GetUser(guid); SetOnlinUser(); } break; case "LD": case "DB": if (Request.Cookies["CurrentUserInfo"] == null) { Response.Redirect(AppSupport.AppPath + "/Support/Login/Default.aspx?url=" + Server.UrlEncode(Request.Url.ToString())); } else { var guid = Request.Cookies["CurrentUserInfo"].Values["CurrentUserGuid"]; GetUser(guid); SetOnlinUser(); } break; } //if (string.IsNullOrWhiteSpace(CurrentUser.UserGuid) || (CurrentUser.UserRole == null)) // Response.Redirect(AppSupport.AppPath + "/SystemOption/lock.html"); //CurrentUser = new CurrentUser("755dd04f-bb9d-44e0-b2f5-07c3986123fb"); } catch (ThreadAbortException exc_) { } catch (Exception ex) { } base.OnLoad(e); }