.net - 如何从.NET检索AD用户的创建日期?

标签 .net active-directory

我想在Active Directory中检索用户的创建日期。我知道用户具有WhenCreated属性,但是我看不到该属性在我正在使用的UserPrincipal类型上公开。

我想做这样的事情:

var principal = UserPrincipal.FindByIdentity(context, IdentityType.Guid, guid);
//var createdDate = principal.CreationDate; 


编辑:这是一个在IIS中运行的Web应用程序,用于查询同一网络上另一台计算机上的AD服务器。

最佳答案

您需要获取基础DirectoryEntry(System.DirectoryServices-命名空间的一部分)。

您可以使用此扩展方法以字符串形式获取日期:

public static String GetProperty(this Principal principal, String property)
{
    DirectoryEntry directoryEntry = principal.GetUnderlyingObject() as DirectoryEntry;
    if (directoryEntry.Properties.Contains(property))
        return directoryEntry.Properties[property].Value.ToString();
    else
        return String.Empty;
}


像这样使用:

var createdDate = principal.GetProperty("whenCreated");

关于.net - 如何从.NET检索AD用户的创建日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2228468/

相关文章:

powershell - 从数组中选择选项

c# - 在 visual studio 2010 中添加安装项目的快捷方式

.net - ASP.NET - OpenIdConnect - 重定向 URI 的格式不正确

c# - TouchMove 事件在 xamarin ios 中结束得如此之快

c# - Windows 窗体加事件目录

c# - 在 C# 中访问/解析 "msDS-AllowedToActOnBehalfOfOtherIdentity"AD 属性

c# - 使用 Sub Select 而不是 INNER JOIN 的 Entity Framework

.net - 通过 SSL : Issue with WCF access due to Third-party Trusted Root Certification Authorities 的 WCF 通信

Powershell-更新属性 "departmentNumber"

java - 目录上下文 : Active Directory Ldap request: get groups of user with parent groups