Search code examples
asp.nethyperlinknavigateurl

How to make a URL relative to a different virtual directory on the same server


I know about the notation that uses a tilde character ~ to represent the root of a website. The links below are part of a virtual directory called "MDWelcome" and while the code below "works", how can I eliminate the "hardcoded" domain name in HyperLink3 below such that it will link to the MDS virtual directory on the "current server" (whatever it is).

<li><asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="http://www.mortgagedataweb.com/MDS/login.asp?default.asp">Subscriber Login</asp:HyperLink></li>
<li><asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="~/faq.aspx">FAQ</asp:HyperLink></li>

p.s. we just "virtualized" this physical webserver and I am trying to test the web from the new virtual machine and this link keeps taking me back to the real physical machine.


Solution

  • Use an absolute path such as the following:

    <li><asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="/MDS/login.asp?default.asp">Subscriber Login</asp:HyperLink></li>
    

    Absolute paths are good practice because they will work as you push your site into different environments or servers.