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

**URL:** <https://discuss.elastic.co/t/an-attempt-was-made-to-access-a-socket-in-a-way-forbidden-by-its-access-permissions-error-come-out/149444>\
**Category:** Elasticsearch\
**Created:** [September 21, 2018, 11:55am UTC](https://discuss.elastic.co/t/an-attempt-was-made-to-access-a-socket-in-a-way-forbidden-by-its-access-permissions-error-come-out/149444 "2018-09-21T11:55:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sangeetshah](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sangeetshah/32/35794_2.png) [@sangeetshah](https://discuss.elastic.co/u/sangeetshah)\
**Post date:** [September 21, 2018, 11:55am UTC](https://discuss.elastic.co/t/an-attempt-was-made-to-access-a-socket-in-a-way-forbidden-by-its-access-permissions-error-come-out/149444/1 "2018-09-21T11:55:39Z")

</div>

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](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:

- [1] BadRequest: Node: [https://elastic:password@url/](https://elastic:password@url/) Took: 00:00:00.0553689

# 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.ValueTask`1.get_Result() at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask`1.get\_Result()  
at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask) at System.Threading.Tasks.ValueTask`1.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:

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [September 23, 2018, 1:52am UTC](https://discuss.elastic.co/t/an-attempt-was-made-to-access-a-socket-in-a-way-forbidden-by-its-access-permissions-error-come-out/149444/2 "2018-09-23T01:52:57Z")

</div>

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

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![sangeetshah](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sangeetshah/32/35794_2.png) [@sangeetshah](https://discuss.elastic.co/u/sangeetshah)\
**Post date:** [September 24, 2018, 5:28am UTC](https://discuss.elastic.co/t/an-attempt-was-made-to-access-a-socket-in-a-way-forbidden-by-its-access-permissions-error-come-out/149444/3 "2018-09-24T05:28:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 22, 2018, 5:28am UTC](https://discuss.elastic.co/t/an-attempt-was-made-to-access-a-socket-in-a-way-forbidden-by-its-access-permissions-error-come-out/149444/4 "2018-10-22T05:28:06Z")

</div>

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