How to get a host name behind a load balancer in A

2019-07-21 14:49发布

问题:

I have a couple of servers and a load balancer. I want to show a server name which is currently serving the page.

I am using HttpContext.Current.Request.ServerVariables["SERVER_NAME"] and HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"] but is shows the same data for all servers (load balancer information is shown but not the information about exact server name).

How to get a relevant information?

回答1:

Try System.Environment.MachineName.



回答2:

Perhaps Server.MachineName does what you are looking for?



回答3:

Page.Request.ServerVariables["HTTP_HOST"].ToUpper();