如何从.NET的AD用户的创建日期? [英] How to retrieve the creation date of an AD user from .NET?

查看:103
本文介绍了如何从.NET的AD用户的创建日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索用户在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");

这篇关于如何从.NET的AD用户的创建日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆