Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检查AD中是否存在完整的列公司_C#_Asp.net Mvc - Fatal编程技术网

C# 检查AD中是否存在完整的列公司

C# 检查AD中是否存在完整的列公司,c#,asp.net-mvc,C#,Asp.net Mvc,请告诉我如何检查用户是否填写了组织字段 我正在制作一本关于MVC5的电话簿。有一个模型和一个控制器 模型 控制器 using System.DirectoryServices; using System.DirectoryServices.AccountManagement; public class PeopleController : Controller { public ActionResult Home(string department)

请告诉我如何检查用户是否填写了组织字段

我正在制作一本关于MVC5的电话簿。有一个模型和一个控制器

模型

控制器

using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;

 public class PeopleController : Controller
    {
        public ActionResult Home(string department)
        {
            IEnumerable<Person> persons = GetPeople();
            return View(persons);
        }

        public static List<Person> GetPeople()
        {

            List<Person> people = new List<Person>();

            var path = new PrincipalContext(ContextType.Domain, "RCSON.local", "OU=RCSON, DC=RCSON, DC=local");

            UserPrincipal user = new UserPrincipal(path);
            user.Enabled = true;

            //user.Name = "*";
            //user.VoiceTelephoneNumber = "*";
            //user.EmailAddress = "*";
            //user.Description = "";
            
            var search = new System.DirectoryServices.AccountManagement.PrincipalSearcher();
            search.QueryFilter = user;
            var results = search.FindAll();
            foreach (UserPrincipal item in results)
            {
                var directoryEntry = item.GetUnderlyingObject() as DirectoryEntry;

                people.Add(new Person
                {
                    DisplayName = item.Name,
                    PhoneNumber = item.VoiceTelephoneNumber,
                    ExtensionPhoneNumber = item.VoiceTelephoneNumber,
                    Email = item.EmailAddress,
                    Office = directoryEntry.Properties["physicalDeliveryOfficeName"].Value as string,
                    Department = directoryEntry.Properties["subdivision"].Value as string,
                    //Title = directoryEntry.Properties["title"].Value as string,
                    DepartmentNumber = Convert.ToInt32(directoryEntry.Properties["departmentNumber"].Value),
                    Subdivision = directoryEntry.Properties["department"].Value as string,
                    Manager = directoryEntry.Properties["manager"].Value as string,
                    Mobile = directoryEntry.Properties["mobile"].Value as string,
                    EmployeeNumber = Convert.ToInt32(directoryEntry.Properties["employeeNumber"].Value)
                });
            }
            return people;
        }
}
使用System.DirectoryServices;
使用System.DirectoryServices.AccountManagement;
公共类PeopleController:控制器
{
公共行动结果主页(字符串部门)
{
IEnumerable persons=GetPeople();
返回视图(人);
}
公共静态列表GetPeople()
{
列表人员=新列表();
var path=newprincipalcontext(ContextType.Domain,“RCSON.local”,“OU=RCSON,DC=RCSON,DC=local”);
UserPrincipal用户=新的UserPrincipal(路径);
user.Enabled=true;
//user.Name=“*”;
//user.VoiceTelephoneNumber=“*”;
//user.EmailAddress=“*”;
//user.Description=“”;
var search=new System.DirectoryServices.AccountManagement.PrincipalSearcher();
search.QueryFilter=用户;
var results=search.FindAll();
foreach(结果中的UserPrincipal项)
{
var directoryEntry=item.getUnderlinegObject()作为directoryEntry;
人物。添加(新人物)
{
DisplayName=项目名称,
PhoneNumber=item.VoicePhoneNumber,
ExtensionPhoneNumber=item.VoicePhoneNumber,
Email=item.EmailAddress,
Office=directoryEntry.Properties[“physicalDeliveryOfficeName”]。值为字符串,
Department=directoryEntry.Properties[“细分”]。值为字符串,
//Title=directoryEntry.Properties[“Title”]。值为字符串,
DepartmentNumber=Convert.ToInt32(directoryEntry.Properties[“DepartmentNumber”].Value),
细分=directoryEntry.Properties[“department”]。值为字符串,
Manager=directoryEntry.Properties[“Manager”]。值为字符串,
Mobile=directoryEntry.Properties[“Mobile”]。值为字符串,
EmployeeNumber=Convert.ToInt32(directoryEntry.Properties[“EmployeeNumber”].Value)
});
}
还人,;
}
}
[在此处输入图像描述][1] [1]: https://i.stack.imgur.com/kv2vh.jpg


如何筛选具有组织名称的用户。

是否要按属性筛选?我不明白。组织名称是什么?广告有“公司”或“组织”字段。我需要按此字段选择用户。什么是广告?公司或组织字段在哪里?我在这篇文章中看不到。广告是Active Directory。
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;

 public class PeopleController : Controller
    {
        public ActionResult Home(string department)
        {
            IEnumerable<Person> persons = GetPeople();
            return View(persons);
        }

        public static List<Person> GetPeople()
        {

            List<Person> people = new List<Person>();

            var path = new PrincipalContext(ContextType.Domain, "RCSON.local", "OU=RCSON, DC=RCSON, DC=local");

            UserPrincipal user = new UserPrincipal(path);
            user.Enabled = true;

            //user.Name = "*";
            //user.VoiceTelephoneNumber = "*";
            //user.EmailAddress = "*";
            //user.Description = "";
            
            var search = new System.DirectoryServices.AccountManagement.PrincipalSearcher();
            search.QueryFilter = user;
            var results = search.FindAll();
            foreach (UserPrincipal item in results)
            {
                var directoryEntry = item.GetUnderlyingObject() as DirectoryEntry;

                people.Add(new Person
                {
                    DisplayName = item.Name,
                    PhoneNumber = item.VoiceTelephoneNumber,
                    ExtensionPhoneNumber = item.VoiceTelephoneNumber,
                    Email = item.EmailAddress,
                    Office = directoryEntry.Properties["physicalDeliveryOfficeName"].Value as string,
                    Department = directoryEntry.Properties["subdivision"].Value as string,
                    //Title = directoryEntry.Properties["title"].Value as string,
                    DepartmentNumber = Convert.ToInt32(directoryEntry.Properties["departmentNumber"].Value),
                    Subdivision = directoryEntry.Properties["department"].Value as string,
                    Manager = directoryEntry.Properties["manager"].Value as string,
                    Mobile = directoryEntry.Properties["mobile"].Value as string,
                    EmployeeNumber = Convert.ToInt32(directoryEntry.Properties["employeeNumber"].Value)
                });
            }
            return people;
        }
}