Solved

Masterpage and site navigation with sub pages

Posted on 2012-04-01
7
587 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
Comment Utility
try modifying like this


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

Author Comment

by:davism
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 1

Author Comment

by:davism
Comment Utility
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
Comment Utility
I think one option is to redirect to www.yourdomain.com
0
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 500 total points
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

12 Experts available now in Live!

Get 1:1 Help Now