阻止母版页自动更正或调整 URL
如何阻止母版页自动更正或调整我的网址?我正在使用站点地图,当母版页位于另一个目录中时,它会弄乱网址。
编辑 我不想在全局范围内执行此操作,我想在单个母版页上执行此操作。
编辑 2 我无权访问这些网址。它们是由站点地图生成的。
编辑 3 当我的母版页位于 \browsers\iphone\
中时。为链接生成的 URL 为 \browsers\iphone\contact-us.aspx
。当站点地图数据绑定到菜单时,该值是正确的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
母版页中的 URL 应相对于根目录,或使用波形符-斜杠
~/
方法来指示从网站根目录开始的路径。如果您的母版页是
/App_Master/MyMaster.master
并且其中有一些链接,请确保它们类似于:而不是诸如:
编辑:
您如何存储您的站点地图?标准 .net XML 站点地图格式?站点地图中的 URL 应始终使用波浪号引用根目录的路径,例如
~/My/Path.aspx
编辑 2:
感谢您澄清数据源和格式。
问题的原因还是存储在站点地图数据源(本例中为 SQL Server)中的 url 不是基于站点根目录的路径。 ASP.NET 站点地图的标准做法是将 URL 存储为
~/mypage.aspx
而不是mypage.aspx
。这与选择的存储格式(xml 与 SQL 数据库等)无关。我仍然建议您考虑使用
~/mypath.aspx
将数据库中的 URL 更新为从根开始。这是标准做法。确实没有理由修改母版页类的功能来不解析 url。请记住,从本质上讲,传统 html 将:
mypage.aspx
视为同一文件夹中../mypage.aspx
视为ASP.NET 在此基础上构建,并带有一个额外的符号:
~/mypage.aspx
使用 url
contact-us 的 .aspx
应该本质上从当前页面构建,因为这就是标准 htmlsrc
和href
路径的工作原理。如果您将站点地图数据源和菜单放在一个普通页面上,嵌套在一个文件夹中,并且忘记使用母版页,您会发现问题仍然存在。很抱歉要争论,但当数据源中的 url 不符合
~/path/to/some/ 的简单格式时,我看不到修改网络上的核心 url 构建功能的价值文件.aspx
。如果我遗漏了什么,也许其他人可以插话......
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:Instead of things like:
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
notmypage.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:
mypage.aspx
as in the same folder../mypage.aspx
as one folder up/mypage.aspx
from the rootASP.NET builds on this with one extra notation:
~/mypage.aspx
from the rootusing the url
contact-us.aspx
should build from the current page by nature as this is how even standard htmlsrc
andhref
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...