Solved

Masterpage and site navigation with sub pages

Posted on 2012-04-01
7
589 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Footer for each row on Gridview 2 21
Sending receiving text messages in vb.net 15 35
How come this regular expression allows "e"? 14 38
C# LINQ ForEach() question 6 28
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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