![](/img/trans.png)
[英]Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously
[英]Timeout issue When Using Active Directory
我正在嘗試做幾件事。 首先,此c#程序使用以下方法針對Active Directory用戶憑據進行驗證:
var ADentry = new DirectoryEntry("LDAP://domain", uname, pword);
但是顯然您需要以某種方式傳遞用戶名和密碼。 有沒有一種方法可以讓您在用戶從Active Directory登錄網絡並在字段中使用它時自動檢索它,而無需在用戶名和密碼中輸入用戶名。
如果沒有,我做到了,以便用戶可以在控制台中輸入其憑據。 但是,如果不起作用,它將永遠掛下去。 如果持續1秒鍾,我可以使用哪種類型的代碼在1分鍾后超時,否則它將永遠掛起? 謝謝
我正在嘗試執行LDAP查詢,以下將為您完成。 大多數都是方法,但是您可能對以下代碼行感興趣: PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sDefaultOU, ContextOptions.Negotiate);
完整的代碼在這里:
IsUserGroupMember("username", "group name the user is in");
public string sDomain = "your.domainName.com"
public string sDefaultOU = OU=**,OU=**,DC=**,DC=**,DC=**
public void IsUserGroupMember(string sUserName, string sGroupName)
{
try
{
UserPrincipal oUserPrincipal = GetUser(sUserName);
GroupPrincipal oGroupPrincipal = GetGroup(sGroupName);
if (oUserPrincipal != null && oGroupPrincipal != null)
{
//do something
}
else
{
//nothing
}
}
catch (PrincipalServerDownException)
{
throw;
}
catch (Exception)
{
throw;
}
}
public UserPrincipal GetUser(String sUserName)
{
PrincipalContext oPrincipalContext = GetPrincipalContext();
UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(oPrincipalContext, sUserName);
return oUserPrincipal;
}
public GroupPrincipal GetGroup(string sGroupName)
{
PrincipalContext oPrincipalContext = GetPrincipalContext();
GroupPrincipal oGroupPrincipal = GroupPrincipal.FindByIdentity(oPrincipalContext, sGroupName);
return oGroupPrincipal;
}
public PrincipalContext GetPrincipalContext()
{
PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sDefaultOU, ContextOptions.Negotiate);
return oPrincipalContext;
}
我希望這段代碼對您有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.