我们将我们的web系统转移到Windows身份验证。在将其部署到生产环境后,我们面临内存泄漏。我们使用poolmon.exe util定义了分页池内存泄漏(tag Toke)。在最近的修改中,我们只增加了2种方法:
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;
}请帮助确定泄漏的确切点,并在可能的情况下提供解决办法。谢谢。
发布于 2013-11-13 09:10:50
方法UserPrincipal.FindByIdentity()存在内存泄漏。
发布于 2013-10-30 11:45:33
PrincipalContext和/或UserPrincipal的实现中可能存在错误,导致无法自动处理实例。我有seen this previously。通过将using替换为try-finally,您可以轻松地确认/修复这个问题,如下所示。
PrincipalContext pc = new PrincipalContext(ContextType.Domain, domainName);
try
{
isValid = pc.ValidateCredentials(login, password);
}
finally
{
pc.Dispose();
}https://stackoverflow.com/questions/19678935
复制相似问题