Reputation: 1708
I searched and feel this is an elementary questions but I can't think straight I guess.
So I have a simple subfolder in my website and pages I need to get to like this.
<a href="Default.aspx">Home</a>
<a href="Subfolder/help.aspx">Help</a>
So when I open my application, I go to the default page where I can click the Help page which takes me to the page in the subfolder, now, if I click on the Home link, it tries to take me to /subfolder/home.aspx ?
I understand what is doing but I don't know I can make the relative path work the way I want it. I can use absolute path but I should not.
Any help please?
Upvotes: 3
Views: 12678
Reputation: 15253
Try this:
<a href="~/Default.aspx" runat="server">Home</a>
<a href="~/Subfolder/help.aspx" runat="server">Help</a>
Now, each link will resolve on the server-side, from the project root downwards.
Upvotes: 2
Reputation: 3599
Relative URLs can be used when linking to pages within your own website. They provide a shorthand way of telling the browser where to find your files.
Repeat the ../
to indicate that you want to go up
folders, then follow it with the file name.
the code below makes the browser jump one folders back from the current folder (ie. that displays current webpage)
<a href="../home.aspx">Home</a>
Since you made a simple subfolder sstructure my guess is that one simple jump will provide the required page. you may jump back two folders using ../../
or three folders using ../../../
and so on until you reach the required folder containing your file.
Or you can use the root link which starts with /
,
such links are know as root-relative links
<a href ="/home.aspx">Home</a>
more about relative links: http://www.motive.co.nz/glossary/linking.php?ref
Upvotes: 2