如何从.NET的AD用户的创建日期?创建日期、用户、NET、AD

由网友(请把我的灵魂交给夏)分享简介:我想检索用户在Active Directory中创建日期。据我所知,用户有一个WhenCreated属性,但我看不到暴露在该属性的 UserPrincipal 的类型我正在与I'd like to retrieve the creation date of users in Active Directory. I u...

我想检索用户在Active Directory中创建日期。据我所知,用户有一个WhenCreated属性,但我看不到暴露在该属性的 UserPrincipal 的类型我正在与

I'd like to retrieve the creation date of users in Active Directory. I understand that users have a WhenCreated property, but I cannot see that property exposed on the UserPrincipal type I am working with.

我希望做这样的事情:

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

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

this is a web application running within IIS, querying an AD server on another machine on the same network.

推荐答案

您需要让底层的DirectoryEntry(的一部分的System.DirectoryServices - 命名空间)。

You need to get the underlying DirectoryEntry (part of the System.DirectoryServices-namespace).

您可以使用此扩展方法来获得日期为一个字符串:

You can use this extension method to get the date as a string:

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");
阅读全文

相关推荐

最新文章