c# - How do I clear System.Net client DNS cache? -
I am using .NET WebRequest while changing my HOSTS file. I see that System.Net does not respect those changes - how can I do this?
I have load-balanced multiple servers behind a hostname, we say 'example.com'. I want to target many of them individually, so my program will give a hard code to machine-specific IP addresses in my hosts file before sending the request to example.com:
163.56. 0.34 example Com For the first server and the first request, it works fine. Then my program replaces the HOSTS file again:
163.56.0.48 example.com And I create a new HttpWebRequest when I send it one , Then I can see in Netman that it goes to the first IP address (163.56.0.34) instead of the expected second place.
By using breakpoints and debug traces, I have confirmed that the correct value of the HOSTS file is written every time when I try to reach example.com from a browser or other program, HOSTS respects the file and goes to the other IP address.
I have verified using NetMon that the IP address was shown directly to the request; There are no HTTP proxies.
Since everything else is honoring the HOSTS file, I strongly suspect that the DNS host-IP Association of example.com's cache has been cached in System.Net Infrastructure. However, I can not find any reference to this caching, and there is no way to flush it or to close it.
I welcome the instructions for dealing with cash, suggesting what may be due to these symptoms, or other proposed clinical steps that can be useful.
I finally decided to open an obscure order from MSDN:
< Code> ServicePoint Manager. DNSReports timefam = 0; As I tried before, I had opened all the strange things, I have been searching for another setting which I need one above; Close the request object, keep it alive:
request.KeepAlive = false;
Comments
Post a Comment