Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

webbrowser not showing host file change

Posted on 2004-10-01
12
Medium Priority
?
350 Views
Last Modified: 2012-06-27
I am working on a program in VS.net that has a main form that calls child forms that contain a webbrowser. Basically, I call the child webbrowser form, have to do some stuff, and close it. Then, I have parent form change the TCP/IP host file. After I change the hostfile, I want to call the child webbrowser again and have it do the same thing but now on a different server (thats why the host file change). Now the host file is getting changed but the webbrowser is not showing the changes.

I put the webbrowser in a child form so that I can close it and hopefully allow it to use the updated host file but its not doing that. Right now, I am disposing the webbrowser in the closing event of the child form as well as disposing the first form before I open up another version of the child webbrowser. However, the host file changes are not being used.

If I close the whole program and restart it again, then the changes show up in the webbrowser.

I know the host file is changed correctly cause I can open up IE and it shows the correct server.

PS: I have to change the host file for this project cause all the servers have the same url.
0
Comment
Question by:admoundc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
12 Comments
 
LVL 19

Expert Comment

by:drichards
ID: 12204688
Rather than change the hosts file, why not use the IP address directly in the URL, since you obviously know it to change the hosts file?  Then you do not have to worry about hosts file caching, which is probably the problem you are experiencing.  I have never looked into how the hosts file is used on Windows.
0
 
LVL 5

Expert Comment

by:naiea1231
ID: 12205840
Yes, i'd recommend using either the ip addresses, or what you could do is modify the hosts file to actually use a different url for each server, so server1 could correspond to the ip of server 1 and server2 would be the ip address of server 2. This would work quite easily in a script environment using incrementation. However, if you do need to modify the hosts file and the above is not an option, then, is there anyway to actually destroy the child window (and does the iexplore.exe run as a process when you launch it as a child? if this occurs you can terminate the process). Another option is to simple automate the relaunching of the program as once the host file change as occured, a relaunch could be a viable option.
0
 

Author Comment

by:admoundc
ID: 12208288
I can't set each server to different IP's or urls that because there are several different servers with the same info on them. I need to test each one. However, the severs have load balancing (or some other stuff, I'm not sure.) that jumps the user back onto a specific url. So, all of these servers jump the user to that one specific url and unless that url is set in the host file, it will go to a random server. I have tried using ip's and different urls in the host file, it won't work.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 19

Expert Comment

by:drichards
ID: 12209730
>> I can't set each server to different IP's
That's exactly why you are wanting to change the hosts file.  You want the same host name to point to different IP's at different times.

>>I have tried using ip's and different urls in the host file, it won't work.
Unless the server needs the DNS name in the HTTP Host header, there is no difference between setting the IP explicitly in the URL (don't need hosts file) and changing the hosts file.  Load balancing won't matter.  With Google for example, you get a different IP each time you query for www.google.com as long as you wait until your DNS cache expires.  If you go directly to an IP, however, you always connect to the same server.  Virtual servers may matter as that will look at the Host header to determine which site is being accessed.  The IP is not sufficient.
0
 

Author Comment

by:admoundc
ID: 12218219
What I meant was, I can't set each server to different IP's at the same time becuase they all bounce the user back to a specific url. So, if I set like 5 different server ip's to 5 different urls in the host, I can start out on each specific server but as you go through the webpages, you get bounced back to the default url(server). The only way I can stay on the server I want is to set that url in the host file.

To put it another way, I have 5+ ip's I have to set to the same url.
0
 
LVL 5

Expert Comment

by:naiea1231
ID: 12229230
Okay, looking at what you've already done i would have assumed that disposing of it then recreating would have looked at the new hosts file but this is, unfortunately, not the case. The only thing i can see is that you mentioned if you close the program again and reopen it then the changes can be seen. In that case, how about you do exactly that but automate the process? change the hosts file, close the application and reopen it, although you will have to develop a method to transfer variables (text files, registry, something external perhaps). Could be worth a try.
0
 

Author Comment

by:admoundc
ID: 12278260
That is an idea I have considered already but I really do not want to add a third layer to the program.
0
 
LVL 4

Accepted Solution

by:
ostdp earned 2000 total points
ID: 12380196
Just run "ipconfig /flushdns" before you try to access the host that was changed/added/deleted. This will force the DNS resolver cache to be refreshed (including reloading the host file). I am not sure how to achive the same on a Win32 API level, but you may want to consult MSDN on that. Worst case scenario just use CreateProcess or WinExec to execute the above.
0
 
LVL 5

Expert Comment

by:naiea1231
ID: 12592593
In my opinion, it seems like ostdp has the solution here, i've tested it out and the hosts file did refresh, so i'd say points should go to him/her.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Six Sigma Control Plans

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question