Reputation: 1810
When my pages are in the main level of the solution, the menu item href can find the content pages. When I put the content pages in a subfolder and change the href path respectively it cannot find the page. This seems to only be a problem with MasterPages. Am I missing something here? I get the error Server Error in '/' Application The resource cannot be found HTTP 404. Requested URL: /Pages/Pages/Items.aspx
Why does it add another /Pages in front of my path?
Solution
Project
+Images
-Pages
Items.aspx
Library.aspx
+Styles
Default.aspx
Site.Master
MasterPage
<div id="tabdiv" class="tabdiv">
<ul id="tabmenu" class="tabmenu">
<li><a href="Pages/Items.aspx" class="separator">Items</a></li>
<li><a href="Pages/Library.aspx">Library</a></li>
</ul>
</div>
<div id="main" class="main">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
Upvotes: 3
Views: 5725
Reputation: 75
Give a path like this.Include your Domain name.
<li><a href="http://example.com/Pages/Items.aspx" class="separator">Items</a></li>
Or You should use XML file or website path file.
Upvotes: 0
Reputation: 759
If your tag is "a href" you must put runat = "server"
with their respective id = "lnkItem"
then the code of the page from the server side you should write:
lnkItem.HRef = ResolveUrl("~/Pages/Items.aspx");
If you are calling to another site you can use 'ResolveUrl':
Response.Redirect(ResolveUrl("~/Pages/Items.aspx"));
Upvotes: 0
Reputation: 32571
Remove the Pages from the href
. The master page is a wrapper for the .aspx
pages' content, but you should use the relative path to the .aspx page when you provide the links inside the master page (given that all your pages are inside the Pages folder):
<li><a href="Items.aspx" class="separator">Items</a></li>
<li><a href="Library.aspx">Library</a></li>
Another option would be to prefix with /
, which will render the link by using the root-relative link/root link/web-root relative link:
<li><a href="/Pages/Items.aspx" class="separator">Items</a></li>
<li><a href="/Pages/Library.aspx">Library</a></li>
Upvotes: 0
Reputation: 2035
Use thge above
<a href="<%= Page.ResolveUrl("~/Pages/Items.aspx") %>" class="separator">Items</a>
Upvotes: 1
Reputation: 101614
Short answer, use an absolute path (to the root of your site) or use ~/
to relate all pages back to the site root (latter being more secure and robust between server location changes).
Reasoning?
/
) linking to Pages/Items.aspx
combines these two: /Pages/Items.aspx
.Pages/
you're now re-citing the same directory Pages/Items.aspx
so you're getting a combined value of /Pages/Pages/Items.aspx
.When you want to link to items, have a look at the Control
.ResolveUrl
method. e.g.
<a href="<%= Page.ResolveUrl("~/Pages/Items.aspx") %>" class="separator">Items</a>
Now, no matter what page that link is embedded it, it still will provide an absolute path to that resource (in this case, Items.aspx).
Upvotes: 5
Reputation: 457
try like this
<li><a href="~/Pages/Items.aspx" class="separator" runat="server">Items</a></li>
<li><a href="~/Pages/Library.aspx" runat="server">Library</a></li>
Upvotes: 3