views:

33

answers:

1

How can I stop a master page from auto-correcting or adjusting my urls? I am using a site map and when the master page is in another directory, it messes it up the urls.

Edit I don't want to do this globally, I want to do this on an individual master page.

Edit 2 I do not have access to the urls. They are generated by a sitemap.

Edit 3 When my master page is in \browsers\iphone\. The URL generated for the links is \browsers\iphone\contact-us.aspx. When the sitemap is databound to the menu, the value is correct.

+1  A: 

Urls in your master page should either be relative to the root, or use the tilde-slash ~/ approach, to indicate the path from the root of the site.

If you master page is /App_Master/MyMaster.master and you have some links in it, ensure they are like:

<link rel="Stylesheet" type="text/css" href="/Path/From/The/Root.css" />
<script type="text/javascript" src="/Path/From/The/Root.js" ></script>

<a href="/Path/From/TheRoot.html">A non server-side link should start in forward slash and provide entire path</a>

<asp:HyperLink ID="MyHyperLink" runat="server" NavigateUrl="~/Path/to/Page.aspx" Text="Use the tilde-slash and use path from site-root"/>

Instead of things like:

<link rel="Stylesheet" type="text/css" href="../SomeRelative/Path.css" />
<script type="text/javascript" src="Path/Not/From/The/Root.js" ></script>

EDIT:

How are you storing your sitemap? The standard .net XML sitemap format? Your URLs in the sitemap should always reference paths from the root using tildes, such as ~/My/Path.aspx

EDIT 2:

Thanks for clarifying the datasource and format.

The cause of the issue is again that the urls stored in the site map datasource (SQL Server in this case) are not paths based on the root of the site. It is standard practice with asp.net sitemaps to store the urls as ~/mypage.aspx not mypage.aspx. This is irrespective of chosen storage format (xml vs SQL database, etc.)

I'd still recommend you consider updating your urls in your database to be from the root using ~/mypath.aspx. This is standard practice. There is really no reason to modify the functionality of the masterpage class to not resolve the urls.

Remember, by nature, traditional html treats:

  • the relative url mypage.aspx as in the same folder
  • the relative url ../mypage.aspx as one folder up
  • the url /mypage.aspx from the root

ASP.NET builds on this with one extra notation:

  • the url ~/mypage.aspx from the root

using the url contact-us.aspx should build from the current page by nature as this is how even standard html src and href paths work. If you put your sitemapdatasource and a menu on a plain page, nested in a folder, and forget about using a master page, you'll find the problem still persists.

Sorry to be argumentative, but I just don't see the value in modifying core url building functionality on the web, when the urls in the datasource aren't conforming to a simple format of ~/path/to/some/file.aspx.

Perhaps someone else can chime in if I'm missing something...

KP
I do not have control of the urls. They are generated by the sitemap.
Daniel A. White
My sitemap is using a sql data source with some url rewriting in the mix.
Daniel A. White
Can you then explain exactly how the master page is manipulating the urls? A before-after example would help.
KP
@KP updated....
Daniel A. White
Ok. In your database, are the urls stored as `contact-us.aspx`, or `~/contact-us.aspx`?
KP
They are stored as contact-us
Daniel A. White