ValidateCredentials() returns FALSE on First Call but TRUE on Subsequent Calls

柔情痞子 提交于 2019-12-23 05:49:33

问题


I'm using the following code to authenticate users on my web service:

using (PrincipalContext context = new PrincipalContext(ContextType.Domain, domain))
{
    return context.ValidateCredentials(userName, password);
}

The obstacle I'm running into is that the first call to ValidateCredentials() is returning false but subsequent calls return true. I placed a breakpoint at this line and in the Intermediate window I see the same results: first call returns false, second returns true, even though nothing was changed (by me) between calls.

The 'domain' is String.Empty but I've also tried it with the actual domain name and get the same results.

I'm not that versed in network administration so any help would be appreciated,


回答1:


I had the a similar problem with a program to control other machine process's.

I had a piece of code that stalls until login method succeded:

do
{
}
while(!login(usrname, pass));

it does not explain whatever studd is happening but it solved my issue...



来源:https://stackoverflow.com/questions/2473222/validatecredentials-returns-false-on-first-call-but-true-on-subsequent-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!