title: Different Ways To Get The Server Name In ASP.NET
body: <p>I want to log my server name in ASP.NET Application, I use multi-servers and load balancing so I need to log the server name.</p>
  
  <p>But what is the difference between these ways to get the server name? </p>
  
  <p>and which one is true or better to log? </p>
  
  <p>any idea? </p>
  
  <p>or any other ways?</p>
  
  <pre><code>System.Environment.MachineName
  Server.MachineName
  System.Net.Dns.GetHostName()
  </code></pre>
  
  <p>There is also another ways but not always return correct server name:</p>
  
  <pre><code>Request.ServerVariables["SERVER_NAME"]
  System.Net.Dns.GetHostEntry(Request.ServerVariables("SERVER_NAME")).HostName
  System.Net.Dns.GetHostEntry(Request.ServerVariables("LOCAL_ADDR")).HostName
  </code></pre>