tags:

views:

82

answers:

3
+3  Q: 

Ignore hosts file?

I need to call a Response.Redirect method from C# but I need to do it in such a way that it ignores the Hosts file on windows for this call?

For example, if on Hosts I have:

127.0.0.1 google.com

and I call a Response.Redirect("google.com"), I need it to ignore the hosts just for this one call and actually go to google.com rather than localhost. How could I do this?

I know I could call a Response.Redirect on google's IP address but is there a better way?

+2  A: 

The only to ignore the hosts file, is to delete it.

leppie
Or comment out the offending line. Anyway, some programs (e.g. web browsers) keep their own DNS cache in addition to the OS's resolver, so changes to `hosts` aren't guaranteed to "take" immediately.
Piskvor
+3  A: 

No, probably not: DNS lookup is handed over to your OS, which checks...hosts file.

Iff you can

  • look up the IP address without the OS's resolver
  • and the target server accepts IP address instead of hostname (some webservers will refuse to serve http://10.15.6.4/some/path (Google Search accepts an IP hostname and works, btw)),

then it might work.

Piskvor
A: 

If you can know the IP address of the host without asking the OS ( e.g. via 3rd party ) .. then you actually ignored the hosts files .

dejavu