久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

C# 使用不同的用戶憑據訪問活動目錄

C# accessing active directory with different user credentials(C# 使用不同的用戶憑據訪問活動目錄)
本文介紹了C# 使用不同的用戶憑據訪問活動目錄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我們剛剛為用戶提供了一個新的用戶創建應用程序.然而,這些用戶需要能夠通過應用程序創建用戶,即使他們自己沒有創建用戶的權限.

There is a new user creation application that we have just provided our users. However these users need the ability to creation users through the application even though they themselves do not have permission to create users.

在 C# 中,您如何模擬其他用戶以獲得此功能.此應用程序主要使用 System.DirectoryServices.

In C# how do you impersonate another user in order to have this functionality. This application primary using System.DirectoryServices.

代碼片段:

DirectoryEntry dEntry = new DirectoryEntry("LDAP://OU=");
DirectorySearcher dSearcher = new DirectorySearcher(dEntry);
//filter just user objects
dSearcher.SearchScope = SearchScope.Subtree;
dSearcher.Filter = "(&(objectClass=user)(mail=" + excel_Holding_Table.Rows[i]["EmailAddress"].ToString() + "))";
dSearcher.PageSize = 1000;
sResults = dSearcher.FindAll();

推薦答案

您可以使用 DirectoryEntry 類直接指定用戶名和密碼:

You can use the DirectoryEntry class directly and specify the username and password:

DirectoryEntry de = new DirectoryEntry(path);

de.Username = "username";
de.Password = "password";

并從 de 對象訪問 Active Directory.或者您可以使用 WindowsIdentity 類并模擬用戶:

And access Active Directory from the de object. Or you can use the WindowsIdentity class and and impersonate a User:

WindowsIdentity newId = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
WindowsImpersonationContext impersonatedUser = newId.Impersonate();

完整代碼示例位于:

模擬和目錄條目

這篇關于C# 使用不同的用戶憑據訪問活動目錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應該總是在 C# 中使用可空類型)
C# HasValue vs !=null(C# HasValue vs !=null)
C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有沒有更高效的語法?)
How to set null value to int in c#?(如何在c#中將空值設置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調用)
主站蜘蛛池模板: 国产视频久久 | 国产欧美日韩一区 | 欧美精品一区二区三区在线 | 91精品久久久久 | 国产东北一级毛片 | 欧美一区二区三区精品免费 | 97精品一区二区 | 午夜欧美a级理论片915影院 | 欧美人妇做爰xxxⅹ性高电影 | 婷婷丁香综合网 | 久久久免费在线观看 | 精品久久香蕉国产线看观看亚洲 | www免费视频 | 久久综合婷婷 | 欧美高清视频一区 | 亚洲欧美日韩电影 | 91色在线| 天堂在线www| 久久9热| 国产精品国产成人国产三级 | 久久精品一| 在线观看亚 | 欧美成人h版在线观看 | 欧美xxxx色视频在线观看免费 | 国产成人免费观看 | 免费精品视频一区 | 一级黄色片毛片 | 久久久久国产一级毛片高清网站 | 色天天综合 | 国产一区二区三区免费 | 视频一区在线 | 在线观看视频91 | 久久一二区 | 黄色大片免费网站 | 国产成人免费视频网站高清观看视频 | 成人av在线播放 | 国产日韩欧美 | 国产激情偷乱视频一区二区三区 | 中文字幕在线一区二区三区 | 久久精品亚洲精品国产欧美 | 亚洲品质自拍视频网站 |