title: SocketException: No connection could be made because the target machine actively refused it on IIS
body: <p>I am having this issue more than few days now, and it's very frustrating. I am using a MVC web API application which is working on local and dev server, but unfortunately when I wanted it to deploy on the staging server, I badly got stuck with this issue. Below is the code and options I have tried so far:</p>
  
  <pre><code>  private HttpResponseMessage ExecutePostRequest(string url, string body)
      {
          try
          {
              HttpContent Body = new StringContent(body);
              Body.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
              HttpClient client = new HttpClient();
              client.DefaultRequestHeaders.Add("Accept", "application/json");
              client.DefaultRequestHeaders.Add("Autorization", "Bearer" + "AccessToken");
              HttpResponseMessage response = client.PostAsync(url, Body).Result;
              return response;
          }
          catch (Exception e)
          {
              WriteLogs(e.ToString(), "Exception");
              throw;
          }
  
      }
  </code></pre>
  
  <p>URL I am passing is of some public API like (<a href="https://api.powerbi.com/beta----" rel="nofollow noreferrer">https://api.powerbi.com/beta----</a>)</p>
  
  <ul>
  <li>Windows Firewall is off</li>
  <li><p>I used Proxy settings as below but nothing worked : </p>
  
  <p></p>
  
  <pre><code> &lt;defaultProxy&gt; &lt;proxy usesystemdefault="true"   proxyaddress="https://api.powerbi.com"   bypassonlocal="True"/&gt; &lt;/defaultProxy&gt;&lt;/system.net&gt;
  </code></pre></li>
  </ul>
  
  <p>The above code gives exception as "The ServicePointManager does not support proxies with the https scheme."</p>
  
  <ul>
  <li><p>I even checked my IE LAN settings. It is not using any proxy settings.</p></li>
  <li><p>Below is the Stack Trace</p>
  
  <p>[SocketException (0x274d): No connection could be made because the target machine actively refused it]
     System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state) +996
     System.Net.Sockets.Socket.UnsafeBeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state) +75
     System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket&amp; socket, IPAddress&amp; address, ConnectSocketState state, IAsyncResult asyncResult, Exception&amp; exception) +480</p>
  
  <p>[WebException: Unable to connect to the remote server]
     System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext&amp; context) +3366493
     System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) +155</p>
  
  <p>[HttpRequestException: An error occurred while sending the request.]</p>
  
  <p>[AggregateException: One or more errors occurred.]
     System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) +5863512
     SignalR.Dal.Repositories.DashboardRepository.ExecutePostRequest(String url, String body) +475
     SignalR.Dal.Repositories.DashboardRepository.GetNominations() +1970
     Signal.WebApi.MvcApplication.Application_Start() +359</p>
  
  <p>[HttpException (0x80004005): One or more errors occurred.]
     System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12600941
     System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
     System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
     System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
     System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475</p>
  
  <p>[HttpException (0x80004005): One or more errors occurred.]
     System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12617988
     System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
     System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12457605</p></li>
  </ul>