title: Router Port Forwarding and HttpContext.Current.Request.Url
body: <p>Here's the scenario. We have a router that port forwards requests for our different test sites. For example <a href="http://www.ourSite.com:8051" rel="nofollow noreferrer">http://www.ourSite.com:8051</a> forwards from the router to a web server that is on port 80. The test web sites are virtual directories of one web site running on IIS6 (Windows Server 2003).</p>
  
  <p>Part of our application send out e-mails that use a base url to build some links in the application. Here's the base url being built in our on application start:</p>
  
  <pre><code>siteBaseUrl = string.Format("{0}://{1}{2}",
                  HttpContext.Current.Request.Url.Scheme,
                  HttpContext.Current.Request.Url.Authority,
                  HttpContext.Current.Request.ApplicationPath.TrimEnd('/'));
  </code></pre>
  
  <p>So let's say one of our tests site's looks like this, <a href="http://www.ourSite.com:8051/client1" rel="nofollow noreferrer">http://www.ourSite.com:8051/client1</a>. I would expect siteBaseUrl to look like this, <a href="http://www.ourSite.com:8051/client1" rel="nofollow noreferrer">http://www.ourSite.com:8051/client1</a>, when in fact it ends up looking like this <a href="http://www.ourSite.com/client1" rel="nofollow noreferrer">http://www.ourSite.com/client1</a> (I tried finding a question like this on StackOverflow but found none. Maybe I wasn't searching with the right keywords, or I need more coffee. Any help on this matter would be greatly appreciated.</p>