3

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!

2 Answers 2

6

How about System.Environment.MachineName

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I was able to get the host name, filter/map the host name and output it as a comment.
3

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.

1 Comment

Note that the first approach is not reliable (like any other HttpRequest based solution as well). It may return "::1" if the user opened the page from localhost.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.