title: HttpContext.Current.Request.UserHostName is empty when called from a class
body: <p>I have various web pages that need to build up a URL to display or place it in an emitted email message. The code I inherited had this value for the name of the webserver in a Public Const in a Public Class called FixedConstants. For example:</p>
  
  <pre><code>Public Const cdServerName As String = "WEBSERVERNAME"
  </code></pre>
  
  <p>Trying to improve on this, I wrote this:</p>
  
  <pre><code>Public Class UIFunction
  Public Shared myhttpcontext As HttpContext
  Public Shared Function cdWebServer() As String
      Dim s As New StringBuilder("http://")
      Dim h As String
      h = String.Empty
      Try
          h = Current.Request.ServerVariables("REMOTE_HOST").ToString()
      Catch ex As Exception
          Dim m As String
          m = ex.Message.ToString()   'Ignore this should-not-occur thingy
      End Try
      If h = String.Empty Then
          h = "SomeWebServer"
      End If
      s.Append(h)
      s.Append("/")
      Return s.ToString()
  End Function
  </code></pre>
  
  <p>I've tried different things while debugging such as HttpContext.Current.Request.UserHostName and I always get an empty string which pumps out my default string "SomeWebServer". </p>
  
  <p>I know Request.UserHostName or Request.ServerVariables("REMOTE_HOST") works when invoked from a page but why does this return empty when invoked from a called method of a class file (i.e. UIFunction.vb)? </p>