Skip to content
Advertisement

Sending a request with Windows Authentication from ASP.NET service

I have a working Python script which sends a request to an web service using Windows Authentication in order to get a token.

The bit that I’m trying to replicate is:

JavaScript

I have an ASP.NET Core service which tries to do it this way:

JavaScript

Right now I am getting the following error: WinHttpException: Error 12029 calling WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, ‘A connection with the server could not be established’.

However, if I comment // handler.ServerCredentials = CredentialCache.DefaultNetworkCredentials;, then I get Error 401 Unauthorised. I also noticed that CredentialCache.DefaultNetworkCredentials is NULL.

Can you please let me know what I am missing here? Thanks.

Advertisement

Answer

Actually, the authentication worked fine, but the request was redirecting to a service which refuses to connect. The easy fix to this was to just disable redirecting. Also, at @spzvtbg’s suggestion, I used the default HttpClienthandler.

The final code ended up like this:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement