/// <summary> /// фильтр логов кто куда ходил и когда /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { userdbContext db = new userdbContext(); var request = filterContext.HttpContext.Request; //logs log = new logs() //{ // dataTime = DateTime.Now, // events = "зашел на эту страницу", // UserName = "******", // pc_ip = PC.GetIPAddress(), // pc_name = System.Net.Dns.GetHostName(), // Url = request.RawUrl //}; //using (userdbContext db = new userdbContext()) //{ // db.logs.Add(log); // db.SaveChanges(); //} try { db.logs.Add(new logs() { dataTime = DateTime.Now, events = "зашел на эту страницу", UserName = (request.IsAuthenticated) ? filterContext.HttpContext.User.Identity.Name : "null", pc_ip = PC.GetIPAddress(), pc_name = System.Net.Dns.GetHostName(), Url = request.RawUrl }); db.SaveChanges(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
static public void FromADtoBD() { userdbContext db = new userdbContext(); try { string domain = "isea.ru"; DirectoryEntry adRoot = new DirectoryEntry("LDAP://" + domain, null, null, AuthenticationTypes.Secure); DirectorySearcher search = new DirectorySearcher(adRoot); search.Filter = "(&(objectClass=user)(objectCategory=person))"; search.PropertiesToLoad.Add("samaccountname"); search.PropertiesToLoad.Add("mail"); search.PropertiesToLoad.Add("memberOf"); search.PropertiesToLoad.Add("displayname");//first name SearchResult result; SearchResultCollection resultCol = search.FindAll(); if (resultCol != null) { for (int counter = 0; counter < resultCol.Count; counter++) { result = resultCol[counter]; if (result.Properties.Contains("samaccountname") && result.Properties.Contains("mail") && result.Properties.Contains("displayname") && result.Properties.Contains("memberOf")) { string groups = (String)result.Properties["memberOf"][0]; groups = groups.Replace("CN=", "").Replace("OU=БГУЭП","").Replace("DC=isea","").Replace("DC=ru","").Replace("OU=",""); db.Ad_users.Add(new Ad_users() { Email = (String)result.Properties["mail"][0], UserName = (String)result.Properties["samaccountname"][0], DisplayName = (String)result.Properties["displayname"][0], role = "", group = groups } ); } } db.SaveChanges(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }