What is the best way to determine URL for local/staging/production?
<p>For local testing the url is something like:
<a href="http://localhost:29234/default.aspx" rel="nofollow">http://localhost:29234/default.aspx</a></p>

<p>For staging, the app is in a virtual directory:
<a href="http://stage/OurApp/default.aspx" rel="nofollow">http://stage/OurApp/default.aspx</a></p>

<p>For production, it's the root
<a href="http://www.ourcompany.com/default.aspx" rel="nofollow">http://www.ourcompany.com/default.aspx</a></p>

<p>However, sometimes we need to do a redirect to a particular directory.  We don't always know exactly where we are at.</p>

<p>So, how would I do a redirect to say /subdir1/mypage.aspx?</p>

<p><strong>MORE INFO</strong></p>

<p>I neglected an important item.  This url is sent back to the browser so that some javascript code can perform the redirect. (Odd, I know).  So a regular ResolveUrl("~/pagename.aspx") won't give the full info...</p>

<p><strong>UPDATE 2</strong>
I ended up with the following, which seems to work across the board...  It looks a little ugly though.</p>

<pre><code>StringBuilder buildUrl = new StringBuilder(@"http://");
buildUrl.Append(Request.Url.Host);
if (Request.Url.Port != 80) {
    buildUrl.Append(":");
    buildUrl.Append(Request.Url.Port.ToString());
}
buildUrl.Append(this.ResolveUrl("~/Pages/Customers.aspx"));
buildUrl.Append(String.Format("?AccountId={0}&amp;tabName=Tab2&amp;primaryCustomerId={1}", acctId, custId));
</code></pre>
