简体   繁体   English

如何在负载均衡环境中获取DNS名称?

[英]How to get DNS name in load balancing environment?

I have 4 servers participating in load balancing environment. 我有4台服务器参与负载均衡环境。 The same ASP.NET application is being hosted in each server. 每个服务器都托管相同的ASP.NET应用程序。 I would like to get the DNS Name regardless of the underlying server. 无论基础服务器如何,我都希望获得DNS名称。 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) . 您可以尝试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 . 例如,如果请求网址为http://www.contoso.com/index.htm?date=today则返回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. Environment.MachineName可能是你想要的任何东西 - 没有人说必须通过DNS公开。 Espeically in a hosting environment. 特别是在托管环境中。
  • System.Net.Dns.GetHostName - will return the host name of the machine, no idea how. System.Net.Dns.GetHostName - 将返回机器的主机名,不知道如何。

Anyhjoe, both my not be what is used to access the machine. Anyhjoe,我不是用来访问机器的东西。 THis is pretty much the Url.Host part only, as this came throug hthe request. 这几乎只是Url.Host部分,因为这是通过请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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