![](/img/trans.png)
[英]How to restrict access to a folder to a specific active directory group in an Asp.Net WebForms application?
[英]How to filter a specific group in Active Directory from asp.net c# application
以下代碼可用於獲取我的廣告中列出的所有用戶。 現在,我需要將結果限制為一組。 如何修改以下內容以僅獲取Active Directory中“每個人”組的成員?
背后的代碼:
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4]
{
new DataColumn("givenName", typeof (string)),
new DataColumn("sn", typeof (string)),
new DataColumn("mail", typeof (string)),
new DataColumn("department", typeof (string))
});
using (var context = new PrincipalContext(ContextType.Domain, null))
{
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
foreach (var result in searcher.FindAll())
{
DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
var clsuser = new ClsUsers();
dt.Rows.Add
(
Convert.ToString(de.Properties["givenName"].Value),
Convert.ToString(de.Properties["sn"].Value),
Convert.ToString(de.Properties["mail"].Value),
Convert.ToString(de.Properties["department"].Value)
);
}
grdvList.DataSource = dt;
grdvList.DataBind();
}
}
}
這是它正在填充的gridview:
<asp:GridView ID="grdvList" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="givenName" HeaderText="GivenName" ReadOnly="True" />
<asp:BoundField DataField="sn" HeaderText="sn" ReadOnly="true" />
<asp:BoundField DataField="mail" HeaderText="Email" ReadOnly="true" />
<asp:BoundField DataField="department" HeaderText="Department" ReadOnly="true" />
</Columns>
</asp:GridView>
我嘗試通過更改上下文變量以指定“ Everybody”來稍微修改代碼,但出現錯誤:嘗試代碼mod:
using (var context = new PrincipalContext(ContextType.Domain, null, "CN=Everybody", "DC=mydomain", "DC=org"))
這是錯誤:
System.DirectoryServices.AccountManagement.PrincipalOperationException:'發生本地錯誤。
看完SO上的其他十二個線程后,今天早晨我偶然發現了一個回答了我問題的問題…… 獲取AD組的成員 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.