Solved

Masterpage and site navigation with sub pages

Posted on 2012-04-01
7
588 Views
Last Modified: 2012-04-02
Hi all,

I have a question and I hope somebody can provide some direction on this and help me get through it.

It deals with a site with a master page but there are several pages that use the master but I have a few sub pages (pages in a sub directory) that I am having trouble with.

The main site has a master page and in it I have some fundamental navigation to like "Home" which is an ahref that goes to "default.aspx". But for example I have something like this:

Main site (with the masterpage)
   - Page 1 (which uses the master page)
   - Page 2 (which uses the master page)
   - TestA/TestPage1 (which uses the master page)
   - TestB/TestPage1 (which uses the master page)

Now, if I'm in "Page 1" and I click on the "Home" which is from the MasterPage it goes to the "default.aspx" just fine and everything is good.

If I'm in "Page 2" and I click on the "Home" which is from the MasterPage it works fine as well and goes to the "default.aspx".

However, and this is there the problem is:

If I'm in TestA/TestPage1 and click on the "Home" which is from the MasterPage it fails because there is no "TestA/default.aspx". The "default.aspx" is in the directory above that. Now, if I change the MasterPage to use "../default.aspx" then it will work but the other pages "Page 1" and "Page 2" will not.

If I'm in TestB/TestPage1 and click on the "Home" which is from the MasterPage it fails because there is also no "TestB/default.aspx". The "default.aspx" is in the directory above that. Now, if I change the MasterPage to use "../default.aspx" and the TestA/TestPage1 will work but the other pages "Page 1" and "Page 2" will not.

How do I get the TestA/TestPage1 and TestB/TestPage1 to use the "default.aspx" in the Masterpage for the "default.aspx" in the root?

Also, I want to avoid using the SiteMap functionality, if at all possible.

Any assistance on this would be greatly appreciated.

Thanks,
0
Comment
Question by:davism
7 Comments
 
LVL 21

Expert Comment

by:masterpass
ID: 37794322
try modifying like this


href="~/Default.aspx"
0
 
LVL 1

Author Comment

by:davism
ID: 37794408
I tried that as well and the same result. It was still trying go to:

TestA/default.aspx

or

TestB/default.aspx

Any other ideas or suggestions or anybody else have any?
0
 
LVL 21

Expert Comment

by:masterpass
ID: 37794426
well that is weird .. I had a sample project and it works for me!

<a href="~/Default.aspx" >Home</a> will redirect to the default.aspx in the root directory of your application. So double check if you have the default.aspx in the root directory!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:davism
ID: 37794474
I know I have the Default.aspx in the root directory because otherwise I couldn't even get to the main site.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37795343
I think one option is to redirect to www.yourdomain.com
0
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 500 total points
ID: 37796153
Two solutions:

1. Request.Url.GetLeftPart(UriPartial.Authority) and Page.ResolveUrl()

<a href="<%=Request.Url.GetLeftPart(UriPartial.Authority)%><%=Page.ResolveUrl("~/Default.aspx")%>">
        Home</a>  

Open in new window


2. string.Concat(), Request.Url.Authority and Request.ApplicationPath

 <a href="<%= string.Concat("http://",this.Context.Request.Url.Authority,this.Request.ApplicationPath)%>/Default.aspx">
        Home</a>

Open in new window


Note: Please ensure while typing you do not make any typo mistake or don't leave any space.  Just a precaution.
0
 
LVL 1

Author Closing Comment

by:davism
ID: 37798806
That appears to work. I implemented it in my site and all looks good.

I am going to look at this in more depth for a better understanding.

Thanks much and much appreciated!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now