title: URL 'localhost:port/' issue for asp.net website
body: <p>I am working on a application and i programatically generate menus since i am working on the local machine my website path is like </p>
  
  <p><a href="http://localhost:55954/VirtualPathName/Default.aspx" rel="nofollow">http://localhost:55954/VirtualPathName/Default.aspx</a></p>
  
  <p>Below is the code for generating menus from the database</p>
  
  <pre><code> String sHost, sHostWithPort, sAbsolutePath, sApplicationPath,sAbsoluteUri,sPathAndQuery,sPageID, sLangCode;
  
      sHost = "http://"+HttpContext.Current.Request.Url.Host;
      sHostWithPort = "http://" + HttpContext.Current.Request.Url.Authority;
      sAbsolutePath = HttpContext.Current.Request.Url.AbsolutePath;
      sApplicationPath = HttpContext.Current.Request.ApplicationPath;
      sAbsoluteUri = HttpContext.Current.Request.Url.AbsoluteUri;
      sPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
  
         //Create Top Menu
          StringBuilder sb = new StringBuilder();
          if (dsMenu != null &amp;&amp; dsMenu.Tables.Count &gt; 0 &amp;&amp; dsMenu.Tables[0].Rows.Count &gt; 0)
          {
              for (int i = 0; i &lt; dsMenuRowCount; i++)
              {
                  sb.Append("&lt;div class='divlink' href='" + dsMenu.Tables[0].Rows[i]["PageInternalLinkURL"] + "?PageId=" + dsMenu.Tables[0].Rows[i]["PageId"] + "&amp;Language=" + sLangCode + "'&gt;" + dsMenu.Tables[0].Rows[i]["PageName"] + "&lt;/a&gt;&lt;/div&gt;");
              }
          }
  
          ltrMenu.Text = sb.ToString();
  </code></pre>
  
  <p>Code works fine except that when ever i have to upload the code to the web server i have to modify the  following statement in for loop to</p>
  
  <pre><code>sb.Append("&lt;div class='divlink' href='" + sHostWithPort + dsMenu.Tables[0].Rows[i]["PageInternalLinkURL"] + "?PageId=" + dsMenu.Tables[0].Rows[i]["PageId"] + "&amp;Language=" + sLangCode + "'&gt;" + dsMenu.Tables[0].Rows[i]["PageName"] + "&lt;/a&gt;&lt;/div&gt;"
  </code></pre>
  
  <p>I have to take out the <strong>sApplicationPath</strong> from the website URL so that URL will be like</p>
  
  <p><a href="http://www.xyz.com/Default.aspx" rel="nofollow">http://www.xyz.com/Default.aspx</a></p>
  
  <p>I search to get around this problem but so far i have not been able to fix. Any help is appreciated with the code so that i don''t have to change the path when i upload the file on the web server.</p>
  
  <p>NOTE: - So dumb of me. I found the solution . Thanks Guys</p>
  
  <p>I just removed the following part.<strong><em>+ sHostWithPort + sApplicationPath + "/"</em></strong> </p>
  
  <p>Thanks guys and please don't mark it as -ve some time we tend to make such mistake. I am not sure how to remove the Question.</p>