views:

275

answers:

2

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"&gt;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.

+1  A: 

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.

Aaron
Thanks Aaron. I should have known that.
John Galt
I see that this works but why is this called an absolute path? Seems like inclusion of the domainname.com piece would make it an absolute path where this would be what, a "relative path"?
John Galt
The absolute path starts from the root folder of the site, while relative paths start from the folder that the page.
JB King
+1  A: 

I recommend you do this instead:

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

If this code is inside a UserControl it may not find the root of the virtual correctly without it.

rick schott