This is basically just how it works - the first 2 requests of the handshake the user isnt successfully authenticated yet, so a 401 is expected and totally reasonable.
If you can (somehow) get the browser to always send auth headers (just for this site!) that would remove one of the 401's, the other is unavoidable without ditching NTLM entirely.
The difference between running locally and running in IIS in your case is the authentication module which is intercepting and modifying the headers. If you were to turn off auth in IIS it will also return single 200 responses (this is a test not a solution for obvious reasons).
200/401 in the code which makes the validation really annoying
The 401, 401, 200 will all come from the same socket, in that order. If you look at the response headers on the 401's you should be able to confirm which are expected. Also IIS has a sub-status visible in the access logs and request context from code running in IIS. Pretty sure you can rewrite based on substatus conditions as well as headers - this might help differentiate requests as a last resort?
is there any other way to validate the call to the api was successful
eventually
NTLM uses a keep alive socket to send multiple requests - just keep reading from the socket until a reasonable timeout and store the final response code received.
moving NTLM to the top of the providers list
Im not sure what changing the order would do, but something that jumps out at me - its common for system.webServer/security/authentication/windowsAuthentication
section to be locked so changes at the web.config level will be ignored and need to be applied at the machine.config level.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…