我需要一种方法来查看用户是否是我的.Net 3.5 asp.net c#应用程序中的活动目录组的一部分.
我正在使用msdn的标准ldap身份验证示例,但我真的没有看到如何检查组.
我正在编写以下方法来在C#中添加和删除活动目录中的用户.
void AddUserToGroup(string userId, string groupName);
void RemoveUserFromGroup(string userId, string groupName);
Run Code Online (Sandbox Code Playgroud)
如何最好地实现这些方法?
以下是CodeProject的一些代码.我在这些示例中看不到AD服务器的位置?(在使用LDAP协议时,它是由.NET框架隐式提供的吗?).这些例子值得关注吗?
public void AddToGroup(string userDn, string groupDn)
{
try
{
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://" + groupDn);
dirEntry.Properties["member"].Add(userDn);
dirEntry.CommitChanges();
dirEntry.Close();
}
catch (System.DirectoryServices.DirectoryServicesCOMException E)
{
//doSomething with E.Message.ToString();
}
}
public void RemoveUserFromGroup(string userDn, string groupDn)
{
try
{
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://" + groupDn);
dirEntry.Properties["member"].Remove(userDn);
dirEntry.CommitChanges();
dirEntry.Close();
}
catch (System.DirectoryServices.DirectoryServicesCOMException E)
{
//doSomething with E.Message.ToString();
}
}
Run Code Online (Sandbox Code Playgroud) 以下代码列出了一些(但不是全部)Active Directory组.为什么?
我正在尝试列出所有安全组,通讯组,计算机组等.我是否指定了错误objectClass
?
private static void ListGroups()
{
DirectoryEntry objADAM = default(DirectoryEntry);
DirectoryEntry objGroupEntry = default(DirectoryEntry);
DirectorySearcher objSearchADAM = default(DirectorySearcher);
SearchResultCollection objSearchResults = default(SearchResultCollection);
SearchResult myResult=null;
objADAM = new DirectoryEntry(LDAP);
objADAM.RefreshCache();
objSearchADAM = new DirectorySearcher(objADAM);
objSearchADAM.Filter = "(&(objectClass=group))";
objSearchADAM.SearchScope = SearchScope.Subtree;
objSearchResults = objSearchADAM.FindAll();
// Enumerate groups
try
{
fileGroups.AutoFlush = true;
if (objSearchResults.Count != 0)
{
foreach (SearchResult objResult in objSearchResults)
{
myResult = objResult;
objGroupEntry = objResult.GetDirectoryEntry();
Console.WriteLine(objGroupEntry.Name);
fileGroups.WriteLine(objGroupEntry.Name.Substring(3));
}
}
else
{
throw new Exception("No …
Run Code Online (Sandbox Code Playgroud) 堆栈溢出有几个与此类似的问题,但不完全相同.
我想在win xp计算机上打开或创建一个本地组,并向其添加成员,域名,本地和众所周知的帐户.我还想检查一个用户是否已经是一个成员,这样我就不会两次添加同一个帐户,并且可能会出现异常.
到目前为止,我开始将DirectoryEntry对象与WinNT://
提供程序一起使用.这样可以,但是我仍然坚持如何获得一个组成员列表?
有人知道怎么做吗?或者提供比使用DirectoryEntry更好的解决方案?
.net c# active-directory windows-security active-directory-group
在我的Sharepoint代码中,我通过以下方式显示所有已定义用户的列表:
foreach (SPUser user in SPContext.Current.Web.AllUsers)
{
...
}
Run Code Online (Sandbox Code Playgroud)
最重要的是,我可以将域安全组添加到Sharepoint组(如访问者),从而一次添加许多用户(更简单的管理).但是我的代码在第一次登录之前至少没有看到这些用户(如果他们有足够的权限).在这种情况下,我只能看到域安全组SPUser
对象实例的IsDomainGroup
设置为true
.
是否可以通过Sharepoint获取域组成员而无需借助Active Directory查询(这是我宁愿避免的,因为您可能需要足够的权限来执行此类操作=更多管理:Sharepoint权限+ AD权限).
我正在尝试列出活动目录中的安全组中的每个人,而不使用PowerShell中的CmdLets.我的脚本的奇怪之处在于,如果我列出整个目录,但是如果我尝试使用ldap查询指定我想要列出的内容,则它无法正常工作.我知道我的ldap查询是正确的,因为我在另一个类似的vbs中使用它并且它有效.注释行是我试图放入查询的地方.
$strFilter = "(&(objectCategory=person)(objectClass=user))"
#$strFilter = "(&(objectCategory=person)(objectClass=user)(memberOf=CN=Common Name,OU=User Groups,...,DC=ad,DC=domain,DC=com))" #... is just left out part of query
#$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://CN=Common Name,OU=User Groups,...,DC=ad,DC=domain,DC=com") #... is just left out part of query
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{$objItem = $objResult.Properties; $objItem.name}
Run Code Online (Sandbox Code Playgroud) 我使用此页面中的示例将用户添加到Active Directory组,但在执行时出现"服务器不愿意处理请求"消息的异常
dirEntry.Properties["member"].Add(userDn);
我有两个域,在一个受信任的关系中,我正在尝试从C#Web应用程序进行管理.要做到这一点,我必须冒充两个不同的技术用户,但这样做很好,所以我不会强调代码的那一部分.
为了构建适当且易于管理的文件系统ACL,我必须这样做
There is no such object on the server. (Exception from HRESULT: 0x80072030)
)如果我正在添加来自同一域的用户,则代码可以正常运行,所以我相信我在这里只缺少一些小的部分信息.我使用这个文档作为参考,也看到了这个问题(还有一些引用了这个错误信息),但它们都没有帮助.
代码(删除了try-catch块以使其更简单)
// de is a DirectoryEntry object of the AD group, received by the method as a parameter
// first impersonation to search in domainB
// works all right
if (impersonator.impersonateUser("techUser1", "domainB", "pass")) {
DirectoryEntry dom = new DirectoryEntry("LDAP://domainB.company.com/OU=MyOU,DC=domainB,DC=company,DC=com", "techUser1", "pass");
de.Invoke("Add", new object[] { "LDAP://domainB.company.com/CN=theUserIWantToAdd,OU=MyOU,DC=domainB,DC=company,DC=com" });
// de.Invoke("Add", new object[] { "LDAP://domainA.company.com/CN=anotherUserFromDomainA,OU=AnotherOU,DC=domainB,DC=company,DC=com" });
impersonator.undoImpersonation();
}
// …
Run Code Online (Sandbox Code Playgroud) 实际上很简单的问题:
我目前禁用了IIS匿名访问,用户使用Windows登录自动登录.但是,调用User.IsInRole("Role name")将返回false.我仔细检查了User.Identity.Name()和"角色名称",它应该返回true.
我目前在我的Web.Config中有这个:
更新
我正在调用User.IsInRole("角色名称"),我应该调用User.IsInRole("DOMAIN\Role name")
但是我仍然想知道是否需要<membership>条目?
我应该改变什么?(是否需要<membership>条目?)
<authentication mode="Windows">
<forms
name=".ADAuthCookie"
timeout="10" />
</authentication>
<membership defaultProvider="ADMembershipProvider">
<providers>
<clear/>
<add
name="ADMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionUsername="XXX\specialAdUser"
connectionPassword="xx"
/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="WindowsProvider">
<providers>
<clear />
<add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
Run Code Online (Sandbox Code Playgroud) asp.net authentication roles active-directory active-directory-group
我正在使用ASP.net与C#,并对Active Directory有一点了解.我已经完成了以下步骤编写程序的任务:
ASP.net应用程序被赋予用户的用户名.
应用程序应使用给定的用户名查询用户的所有组.
然后,应用程序应将这些组显示在两个单独的列表中,一个由通讯组组成,另一个列表中包含其余组.
现在,查询所有组很容易.但是,如何检查该组是否在分发组中?
我没有得到更多的信息.
我可以检查的任何属性或东西?
asp.net distribution active-directory active-directory-group