IIS Load Balancing and ASP.Net

 ̄綄美尐妖づ 提交于 2019-12-23 20:33:57

问题


Basically, I have 3 servers where 1 of them serves as a load balancing server.

In my ASPX page, I want to add a HTML comment to show the IP address or even host name of the server selected by the load balancer.

I tried looking through IIS Server variables and tried using SERVER_NAME but that just returns the domain URL.

So, is there any way to do this programming in ASP.NET? Thanks!


回答1:


How about System.Environment.MachineName




回答2:


For IP address:

HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"].ToString(); 

For local server hostname:

System.Net.Dns.GetHostName();

EDIT:

@Conrad's answer above (System.Environment.MachineName) also works for the host name.



来源:https://stackoverflow.com/questions/3399689/iis-load-balancing-and-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!