• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 598
  • Last Modified:

Masterpage and site navigation with sub pages

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
davism
Asked:
davism
1 Solution
 
masterpassCommented:
try modifying like this


href="~/Default.aspx"
0
 
davismAuthor Commented:
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
 
masterpassCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
davismAuthor Commented:
I know I have the Default.aspx in the root directory because otherwise I couldn't even get to the main site.
0
 
CodeCruiserCommented:
I think one option is to redirect to www.yourdomain.com
0
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
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
 
davismAuthor Commented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now