Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.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# 如何在Web表单中使用目录服务?_C#_Asp.net_Active Directory - Fatal编程技术网

C# 如何在Web表单中使用目录服务?

C# 如何在Web表单中使用目录服务?,c#,asp.net,active-directory,C#,Asp.net,Active Directory,基本上,我正在创建一个员工变更请求表单,并希望在列出的选项中加载电子邮件组(用于添加/删除成员身份)。我正在使用Visual C#并尝试创建一个单独的类,该类使用目录服务来完成此任务。当我将该类添加到App_Code文件夹时,它将无法再找到System.DirectoryServices,并给出一个错误。我缺少什么?如果您使用的是.NET 3.5及更高版本,您应该检查System.DirectoryServices.AccountManagement(S.DS.am)命名空间。您需要将其作为.N

基本上,我正在创建一个员工变更请求表单,并希望在列出的选项中加载电子邮件组(用于添加/删除成员身份)。我正在使用Visual C#并尝试创建一个单独的类,该类使用目录服务来完成此任务。当我将该类添加到App_Code文件夹时,它将无法再找到System.DirectoryServices,并给出一个错误。我缺少什么?

如果您使用的是.NET 3.5及更高版本,您应该检查
System.DirectoryServices.AccountManagement
(S.DS.am)命名空间。您需要将其作为.NET引用添加到项目中

请在此处阅读所有相关内容:

基本上,您可以定义域上下文并在AD中轻松找到用户和/或组:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   // do something here....     
}

// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");

// if found....
if (group != null)
{
   // iterate over members
   foreach (Principal p in group.GetMembers())
   {
      Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
      // do whatever you need to do to those members
   }
}

新的S.DS.AM使在AD中与用户和组进行交互变得非常容易:

如果您使用的是.NET 3.5及更高版本,您应该查看
System.DirectoryServices.AccountManagement
(S.DS.AM)命名空间。您需要将其作为.NET引用添加到项目中

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   // do something here....     
}

// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");

// if found....
if (group != null)
{
   // iterate over members
   foreach (Principal p in group.GetMembers())
   {
      Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
      // do whatever you need to do to those members
   }
}
请在此处阅读所有相关内容:

基本上,您可以定义域上下文并在AD中轻松找到用户和/或组:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   // do something here....     
}

// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");

// if found....
if (group != null)
{
   // iterate over members
   foreach (Principal p in group.GetMembers())
   {
      Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
      // do whatever you need to do to those members
   }
}

新的S.DS.AM使得在广告中与用户和组进行交流变得非常容易:

您遇到了什么错误?听起来您正在使用一个网站“项目”。我建议改为使用Web应用程序项目,至少对于任何非琐碎的事情。您会遇到什么错误?听起来您使用的是网站“项目”。我建议改用Web应用程序项目,至少对于任何非琐碎的事情。
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   // do something here....     
}

// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");

// if found....
if (group != null)
{
   // iterate over members
   foreach (Principal p in group.GetMembers())
   {
      Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
      // do whatever you need to do to those members
   }
}