Abe
Abe

Reputation: 6514

IIS Load Balancing and ASP.Net

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!

Upvotes: 3

Views: 1362

Answers (2)

Justin Grant
Justin Grant

Reputation: 46763

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.

Upvotes: 3

Conrad Frix
Conrad Frix

Reputation: 52675

How about System.Environment.MachineName

Upvotes: 6

Related Questions