title: sHow to determine the path of the current web site
body: <p>I wanted to create a function which would return the path of the current web site. This is what I thought was working while running in the IDE:</p>
  
  <pre><code> Public Shared Function WebsiteAbsoluteBaseUrl() As String
  
              Dim RequestObject As System.Web.HttpRequest = HttpContext.Current.Request
  
              Return "http://" &amp; RequestObject.Url.Host &amp; ":" &amp; _
                                 RequestObject.Url.Port &amp; "/" &amp; _
                                 RequestObject.Url.Segments(1)
          End Function
  </code></pre>
  
  <p>this seem like it should work? Is there a more straight forward way?</p>
  
  <p>I am trying to replace all occurrences of the tag "{WebSiteBaseUrl} in an html email with the absolute web site path. </p>
  
  <pre><code>&lt;A HREF="{WebSiteBaseUrl}Files/filename.pdf/&gt;Some Text&lt;/A&gt;
  </code></pre>
  
  <p>I don't want to have to parse the template and try to make sense of it in order to use MapPath function on a relative path to a file name.</p>
  
  <p>The resulting email will become the html body of an html email, so I need the links to be absolute.</p>
  
  <pre><code>&lt;a href="http://websitename:80/SubmitOrder.aspxFiles/filename.pdf" target="_blank"&gt;Some Text&lt;/a&gt;
  </code></pre>
  
  <p>I guess what I am seeing in dev, running in the IDE, is that "RequestObject.Url.Segments(1)" returns the name of the virtual folder and that in production it seems to be returning the name of the web page. I guess this probably has to do with how the web site is set up in IIS. </p>
  
  <p>What does this suggest about how the web site is set up in production and how would you suggest I modify the code to yield a correct path after replacing {WebSiteBaseUrl} with the result of the function? This assumes that the file "filename.pdf" is in the relativepath ~/files/filesname.pdf.</p>