Glory
Glory

Reputation: 461

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?

Upvotes: 3

Views: 2854

Answers (3)

leppie
leppie

Reputation: 117220

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

Upvotes: 2

Piskvor left the building
Piskvor left the building

Reputation: 92752

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.

Upvotes: 3

Ahmed Aman
Ahmed Aman

Reputation: 2393

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 .

Upvotes: 1

Related Questions