Ben*_*Ben 2 .net active-directory
我想检索Active Directory中用户的创建日期.我知道用户有一个WhenCreated属性,但我看不到我正在使用的UserPrincipal类型上公开的属性.
我想做这样的事情:
var principal = UserPrincipal.FindByIdentity(context, IdentityType.Guid, guid);
//var createdDate = principal.CreationDate;
Run Code Online (Sandbox Code Playgroud)
编辑:这是在IIS中运行的Web应用程序,在同一网络上的另一台计算机上查询AD服务器.
Per*_*alt 10
您需要获取基础DirectoryEntry(System.DirectoryServices
-namespace的一部分).
您可以使用此扩展方法将日期作为字符串获取:
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;
}
Run Code Online (Sandbox Code Playgroud)
使用这样:
var createdDate = principal.GetProperty("whenCreated");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6350 次 |
最近记录: |