title: Issues connecting C# app to remote server with Non-Split Tunnel VPN
body: <p>I have C# (.Net 4.5) Winforms app communicates with a webserver hosted on the internet. </p>
  
  <p>It works flawless, until I turn on the VPN, which is restrictive and does not support split tunneling.</p>
  
  <p>It is reproducible only by following these steps:</p>
  
  <ol>
  <li>Start the .Net app and make a HttpWebRequest to a server - this goes through as expected. </li>
  <li>Connect the VPN client. The VPN is configured to route all traffic through the VPN (as opposed to "split tunnelling" for intranet resources)</li>
  <li><p>After the VPN connects, the webrequest stops working in the .NET app. The .NET app starts getting a generic "Unable to connect to the remote server" on <code>HttpWebRequest.GetResponse</code>:</p>
  
  <p><pre><code>
  System.Net.WebException: Unable to connect to the remote server --->
  System.Net.Sockets.SocketException: 
  A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond xxx.xxx.xxx.206:443 
  at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
  at System.Net.ServicePoint.ConnectSocketInternal(Boolean 
  connectFailure, Socket s4, Socket s6, Socket&amp; socket, IPAddress&amp; address, 
  ConnectSocketState state, IAsyncResult asyncResult, Exception&amp; exception)
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.GetResponse()
  at DNSCacheTest.Form1.SendWebRequest(String url)
  </pre></code></p></li>
  </ol>
  
  <p>Turning off VPN, the app starts working and requests go through again.</p>
  
  <p><strong>If the VPN is already connected before the application is started, the problem does not occur.</strong></p>
  
  <p>This applies to any public server, even <a href="https://www.google.com" rel="nofollow">https://www.google.com</a>.</p>
  
  <p>I kept a watch on <code>NetStat</code> log for all these scenarios and here's what I observed:</p>
  
  <ul>
  <li>If I leave the application running and turn VPN ON, the application still tries to connect using old Foreign Address, there by failing.</li>
  <li>If I restart the application with VPN ON, the application now connects with a different proxy foreign address, and works fine.</li>
  </ul>
  
  <p>I create a new <code>WebRequest</code> each time. I tried all possible ways to force the application to use newer address each time, but was unable to do so.</p>
  
  <p>Below are few of the things I tried and didn't work:</p>
  
  <ol>
  <li>Flushed DNS Recovery Cache</li>
  <li>Flushed  ARP Cache</li>
  <li>Deleted Destination Cache</li>
  <li>Tried multiple pings to server through the same .Net app instance.</li>
  <li>Tried adding routes in route table for existing server IP routing to proxy server IP. </li>
  </ol>
  
  <p>Please advice.</p>