I have a program which uses WebRequest for accessing http sites. If I start the program perform some webRequests and then change the Dns settings of my machine, the program will not change dns-servers
Like
WebRequest.Create("http://www.google.com");
....Change Dns settings for my network interface to something invalid or capturing portal....
WebRequest.Create("http://www.google.com");
// Still uses original dns server for dns lookup (or cache)
ipconfig flushdns
makes no difference
Any way I can force the WebRequest to use the actual dns server for dns lookups?
EDIT: It seems that a restart of the windows service for DnsClient cache does the trick. Quite hardcore though
Internally, every server is abstracted by a ServicePoint class. So, once you have created a ServicePoint, either explicitly, or implicitly, it does not change.
Also, it might be caching the previous connection and using it for the subsequent request.
You can try setting
HttpWebRequest.KeepAlive = false
and
HttpWebRequest.ConnectionGroupName = String.Format("connection-{0}", ++index);
and see if that forces .NET to create a new connection every time.
If that doesnt work, try implementing a BindIPEndPointDelegate() method and attaching it to the webrequest. Then, for each request, .NET will call that delegate to resolve the endpoint IPAddress, and you can do a DNS.Resolve() in that delegate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With