![](/img/trans.png)
[英]Get Groups From OU using DirectoryServices.AccountManagement
[英]Memory leaks when using DirectoryServices.AccountManagement
我們將Web系統移至Windows身份驗證。 將其部署到生產環境后,我們面臨着內存泄漏。 我們使用poolmon.exe util將其定義為頁面緩沖的池內存泄漏(標記Toke)。 在最近的修改中,我們僅添加了以下兩種方法:
using System.DirectoryServices.AccountManagement;
private bool IsLoginValid(string login, string password)
{
bool isValid = false;
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domainName))
{
isValid = pc.ValidateCredentials(login, password);
}
return isValid;
}
private bool isMemberOf(string login, string group)
{
bool result = false;
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domainName))
{
using (UserPrincipal user = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, login))
{
if (user != null)
{
result = user.IsMemberOf(pc, IdentityType.Name, group);
}
}
}
return result;
}
請幫助確定泄漏的確切點,並在可能的情況下提供解決方法。 謝謝。
PrincipalContext
和/或UserPrincipal
的實現中可能存在錯誤,導致無法自動處理實例。 我以前看過這個 。 您可以輕松地確認/由替換解決這個問題using
一個try-finally
,如下圖所示。
PrincipalContext pc = new PrincipalContext(ContextType.Domain, domainName);
try
{
isValid = pc.ValidateCredentials(login, password);
}
finally
{
pc.Dispose();
}
方法UserPrincipal.FindByIdentity()
有內存泄漏。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.