简体   繁体   中英

How to get DNS name in load balancing environment?

I have 4 servers participating in load balancing environment. The same ASP.NET application is being hosted in each server. I would like to get the DNS Name regardless of the underlying server. Which one of the followings will give the correct answer?

Request.Url.Host
Environment.MachineName
System.Net.Dns.GetHostName() 

Thanks for your suggestion!

You could try Request.Url.GetLeftPart(UriPartial.Authority) . So for example if the request url is http://www.contoso.com/index.htm?date=today this will return http://www.contoso.com .

The first. It actually is the ONLY one that is even vaguely relevant.

  • Environment.MachineName may be whatever you want - noone says that has to be exposed via DNS. Espeically in a hosting environment.
  • System.Net.Dns.GetHostName - will return the host name of the machine, no idea how.

Anyhjoe, both my not be what is used to access the machine. THis is pretty much the Url.Host part only, as this came throug hthe request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM