【问题标题】:PrincipalContext.ValidateCredentials doesn't set lastLogon date for userPrincipalContext.ValidateCredentials 没有为用户设置 lastLogon 日期
【发布时间】:2013-05-17 10:02:54
【问题描述】:

我正在验证 Active Directory 存储中的用户,如下所示:

// using System.DirectoryServices.AccountManagement;
// located in System.DirectoryServices.AccountManagement.dll

using (var context = new PrincipalContext(ContextType.Domain, server, container, 
    ContextOptions.Negotiate, validateUsername, validatePassword))
{
    var valid = context.ValidateCredentials(validateUsername, validatePassword);
    if (valid)
    {
        Console.WriteLine("SUCCESS!");
        using (var userContext = UserPrincipal.FindByIdentity(context,
               IdentityType.SamAccountName, validateUsername))
        {
            Console.WriteLine("LastLogon = " + userContext.LastLogon);
        }
    }
    else
        Console.WriteLine("FAILED!");
}

验证成功,但lastLogon 值从未更改。当我们在代码中对用户进行身份验证时,必须更改此值,因为其他软件使用此值。我知道ActiveDirectoryMembershipProvider 身份验证会更改此属性,所以我想知道是否有一种方法可以使用PrincipalContext(重用AD 连接)但执行此验证以更改lastLogon 值。

【问题讨论】:

    标签: c# authentication active-directory directoryservices


    【解决方案1】:

    使用lastLogonTimestamp。这是当您尝试通过 PrincipalContext 对象连接时在 AD 中更新的字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-20
      • 2021-02-23
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多