[RESOLVED] Site navigation question
Hi all,
Seems like this should be pretty basic, but it's not working like I am anticipating. Ok I'm developing a ASP.NET web app and I have some links like such:
Code:
<!-- Begin Navigation -->
<div id="navigation">
<ul>
<li><a href="default.aspx">Home</a></li>
<li><a href="nationalhistory.aspx">National History</a></li>
<li><a href="chapterhistory.aspx">Chapter History</a></li>
<li><a href="interest.aspx">Membership Interest</a></li>
<li><a href="events.aspx">Events</a></li>
<li><a href="members/members.aspx">Members Only</a></li>
</ul>
</div>
<!-- End Navigation -->
Clicking the link navigates to that page. However when I click the last link (members only), it navigates just fine to a page in a folder on my site: "members/member.aspx". Problem is after going to this page it keeps the "members/" so when I click one of the other links (ie Home) it trys to go to: "members/default.aspx" instead of just "/default.aspx"
Is there something I'm doing wrong here? I'm using VS 2008 and ASP.NET 2.0.
Thanks,
Strick
Re: Site navigation question
When you link to anything on your website, the links are treated differently depending on what you put in them.
For example, any type of link formatted like the following will use the current directory as its base:
Code:
<a href="default.aspx">Home</a>
The same goes for your example
Code:
<a href="members/members.aspx">Members Only</a>
When you go into the members.aspx page, you're currently in the members folder. So clicking for default.aspx will go to the default.aspx in your folder.
There are a few ways around this.
First, you could use ../. This tells the site you want to go back a level. You can string these together to.
Code:
<a href="../default.aspx">Members Only</a>
This will now work in the members folder but it may or may not work on the root of your site. It also won't work if you decided to nest your folders deeper.
A better solution is using the root of your website as the base directory. To do this you always start with a /. Starting with a slash will referring to the root site no matter where you are. If you're in the following page:
Code:
http://www.mywebsite.com/Store/Categories/Subcategories/Product/Specs.aspx
And you want to reuse an image at your root directory you can do this:
Code:
<img src="/Images/MyImage.jpg" />
Even though you're in the highest directory the / always goes to the root.
You could then update your navigation this way:
Code:
<!-- Begin Navigation -->
<div id="navigation">
<ul>
<li><a href="/default.aspx">Home</a></li>
<li><a href="/nationalhistory.aspx">National History</a></li>
<li><a href="/chapterhistory.aspx">Chapter History</a></li>
<li><a href="/interest.aspx">Membership Interest</a></li>
<li><a href="/events.aspx">Events</a></li>
<li><a href="/members/members.aspx">Members Only</a></li>
</ul>
</div>
<!-- End Navigation -->
It will now work no matter what directory you put the user in.
Re: Site navigation question
Hi, Thanks for your response. I think this will work when I go live. however when I'm in development, VS does this:
http://localhost49200/mysitename/default.aspx
so if I use your sample to go to the root:
<li><a href="/default.aspx">Home</a></li>
it will do this:
http://localhost49200/default.aspx
which it doesn't find and throws an page not found error.
I think this is correct if I'm live cause http://localhost49200 will get replaced with http://www.mysitename.com. But in development it looks like VS forces it this way: http://localhost49200/mysitename/default.aspx
Thanks,
Strick
Re: Site navigation question
Why is your Visual Studio setup that way? I would change it to be just like your production environment; get rid of the mysitename folder.
Just go to Project -> Properties -> Web -> Change Virtual path to just a /
If you leave it the way it is then you'll end up with a site that you cannot test 100% in the two environments which can lead to production problems.
Re: Site navigation question
Hi
Nothing I do will change its behavior. I don't see a
"Just go to Project -> Properties -> Web ->"
Here are how the toolbar reads from left to right:
file > edit > view > website > build > debug > format > tools > test > window > help
Don't see a "project" option.
Thanks,
Strick
Re: Site navigation question
You should have Project settings to specify different things like build types, resources, etc. If you don't have a menu at the top then right click on your project in Solution Explorer and make your changes that way.
Re: Site navigation question
Quote:
Originally Posted by kasracer
First, you could use ../. This tells the site you want to go back a level. You can string these together to.
Code:
<a href="../default.aspx">Members Only</a>
Its also good to note for anyone who is using this notation that not all browers support this format. One for example being netscape.
Re: Site navigation question
Quote:
Originally Posted by kxcntry99
Its also good to note for anyone who is using this notation that not all browers support this format. One for example being netscape.
What version of Netscape are you referring to? It's a very standard feature and a site I worked on 2 years ago heavily relied on it and it worked on all of the recent Netscapes at the time (including several verisons back). Are you referring to an extremely old version of Netscape such as 4?
Re: Site navigation question
Hi all,
I finally found the virtual directory option in VS and set it to /. Thanks for your help.
Strick
Re: Site navigation question
Quote:
Originally Posted by kasracer
What version of Netscape are you referring to? It's a very standard feature and a site I worked on 2 years ago heavily relied on it and it worked on all of the recent Netscapes at the time (including several verisons back). Are you referring to an extremely old version of Netscape such as 4?
I am looking for it now but I thought I had read on MSDN that the ../ was not recognized by Netscape.
Re: [RESOLVED] Site navigation question
There's also ~/ which will send you back to the root based on virtual directory.
That would involve you using <asp:Hyperlink>s though, rather than the regular hyperlink. Giving the regular hyperlink runat="server" and an id might help but I haven't tried it or I don't remember.
Re: Site navigation question
Quote:
Originally Posted by kxcntry99
I am looking for it now but I thought I had read on MSDN that the ../ was not recognized by Netscape.
I guess I was wrong...:blush: Cant seem to find where I saw this before.
Sorry:cry:
Re: Site navigation question
Quote:
Originally Posted by kxcntry99
I guess I was wrong...:blush: Cant seem to find where I saw this before.
Sorry:cry:
No worries and I wouldn't be surprised if this didn't work in some of the very old browsers but it should be widely supported today.