我正在检索Active Directory用户帐户的lastlogon字段。我在还没有在很长一段时间登录帐户的情况下,发现我得到一个异常:如何将lastlogon从AD转换为datetime?
Exception type: ArgumentOutOfRangeException
Exception message: Index was out of range. Must be non-negative and less than the size of the collection.
参数名:指数
的代码如下:
long lastLogon = (long)sr.Properties["lastLogon"][0];
DateTime dtLastLogon = DateTime.FromFileTime(lastLogon);
是有一个适当的方法来施加这个并处理这个异常?
感谢
'lastLogon'的值是什么?它有价值还是0? –
它的值为0,或者(从不) – dotnetdev