Dns settings changed while the program is running

I have a program that uses WebRequest to access http sites. If I run the program by doing some webRequests and then changing the Dns settings of my machine, the program will not change the dns servers

how

WebRequest.Create("http://www.google.com"); 

.... Change the Dns settings for my network interface to something invalid or exciting portal ....

  WebRequest.Create("http://www.google.com"); // Still uses original dns server for dns lookup (or cache) 

ipconfig flushdns doesn't matter

Anyway, can I get WebRequest to use the actual DNS server to look up dns?

EDIT: It seems that restarting the Windows service for the DnsClient cache does the trick. Pretty hardcore though

+4
source share
1 answer

Internally, each server is abstracted by the ServicePoint class. So, once you have created ServicePoint, explicitly or implicitly, it does not change.

In addition, it can cache the previous connection and use it for a subsequent request.

You can try to install

HttpWebRequest.KeepAlive = false

and

HttpWebRequest.ConnectionGroupName = String.Format ("connection- {0}", ++ index);

and see that this forces .NET to create a new connection every time.

If this does not work, try using the BindIPEndPointDelegate () method and bind it to the web request. Then, for each request, .NET will call this delegate to resolve the IP address of the endpoint, and you can do DNS.Resolve () on this one.

+2
source

All Articles