An attempt was made to access a socket in a way forbidden by its access permissions error come out

i have signup into elastic cloud and created account and perform crude opetion into c# project that working fine into local pc but it getting stop working when i deploy this code into online or iis.
i am using elastic loud url and credential to perform all task.

My sample code into my C# Project
var uri = new Uri("https://elastic:password@cloud elastic url");
var settings = new ConnectionSettings(uri).DisableDirectStreaming();
var client = new ElasticClient(settings);

    var response1 = client.ClusterHealth();
    if (response1.DebugInformation != null)
        _logger.Error(response1.DebugInformation    );

Full error message display as below:-
Invalid NEST response built from a unsuccessful low level call on GET: /_cluster/health

Audit trail of this API call:

OriginalException: System.Net.Http.HttpRequestException: An attempt was made to access a socket in a way forbidden by its access permissions ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions

at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask1.get_Result()
at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask1 creationTask) at System.Threading.Tasks.ValueTask1.get_Result()
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at Elasticsearch.Net.HttpConnection.Request[TResponse](RequestData requestData)

Request:

<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>

Response:

Can you try passing the credentials using .BasicAuthentication(...) instead of in the Uri. For example

var uri = new Uri("https://<cloud elastic url>:9243");
var settings = new ConnectionSettings(uri)
    .BasicAuthentication("elastic", "<password>")
    .DisableDirectStreaming();

var client = new ElasticClient(settings);

var response = client.ClusterHealth();

// check .IsValid to see if the request was valid. 
// Don't check .DebugInformation, as it will always have a value...
if (response.IsValid == false)
    _logger.Error(response.DebugInformation);

thanks for contributing @forloop but i already try basicauthontication but it not help me

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.