views:

63

answers:

2

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!

+5  A: 

How about System.Environment.MachineName

Conrad Frix
Thanks! I was able to get the host name, filter/map the host name and output it as a comment.
AbeP
+2  A: 

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.

Justin Grant