站点地图/面包屑未在默认页面上显示 URL 路由
我已经使用 UrlRouting 设置了我的 Web 表单站点 (4.0)。 当我转到
我的主要问题是 http://Localhost/
由于它在 IIS 中默认为 http://Localhost/default.aspx
我试图避免在站点地图 xml 中添加另一个元素,例如
<siteMapNode url="~/Home" title="Home" description="Home" aspx="default.aspx">
最好的使用方法是什么?
我尝试将其添加到我的路由表中使用 xmlSiteMapProvider 来看看我是否可以用它来做一些事情(这不起作用)。
routes.MapPageRoute("IISDefault", "", "~/Default.aspx");
这是一些信息。
Routes
routes.MapPageRoute("Default", "Home", "~/Default.aspx");
routes.MapPageRoute("ListAll", "List", "~/ListAll.aspx");
Sitemap
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/Home" title="Home" description="Home">
<siteMapNode url="~/List" title="List All" description="List All" />
</siteMapNode>
</siteMap>
XmlSiteMapProvider
/// <summary>
/// This is where the original sitemap node is overloaded. We get the proper translation from the database.
/// </summary>
/// <param name="sender">This is the sender of the event</param>
/// <param name="e">This is the event arguments</param>
/// <returns>Returns a modified SiteMapNode</returns>
/// <remarks></remarks>
public SiteMapNode SmartSiteMapProvider_SiteMapResolve(object sender, SiteMapResolveEventArgs e)
{
SiteMapNode returnValue = null;
if ((SiteMap.CurrentNode == null))
{
// If we don't find a sitemap node, then we might be working with UrlRouting
returnValue = ProcessRoute(e);
}
return returnValue;
}
private SiteMapNode ProcessRoute(SiteMapResolveEventArgs e)
{
SiteMapNode returnValue = null;
System.Web.Routing.RequestContext rc = HttpContext.Current.Request.RequestContext;
if ((rc != null))
{
System.Web.Routing.RouteBase route = rc.RouteData.Route;
if ((route != null))
{
// Play with the node (Never getting here)
}
}
return returnValue;
}
编辑:我将看看是否可以操纵routeCollection 以某种方式获得匹配。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是:
尝试这个:
否则“~/”和“~/Home”是同一件事。
或者您可以按原样保留上述内容,并在 default.aspx 页面中执行类似以下操作...
这将有效地将任何默认请求重定向到您的默认请求。
您的问题是服务器将 ~/" 和 "~/Home" 视为 2 个不同的 url,而您基本上希望它们相同,因此您必须做出决定并决定将哪一个重定向到另一个。
就个人而言,如果这是我的解决方案,我不会有“~/Home”的路线,并且站点地图中的基本节点看起来像这样:
“http://yourdomain/”是主页,“http:”是干净且明显的。 //yourdomain/Home”可以是任何东西(关于你的家、我的家、甜蜜的家、我喜欢的东西),而“http://adomain/”是全球每个人的主页。
Instead of :
try this:
Otherwise "~/" and "~/Home" are the same thing.
or you could leave the above as is and in the default.aspx page do something like this ...
That would effectively redirect any default request to your default request.
Your problem is that the server sees ~/" and "~/Home" as being 2 different urls and you basically want them to be the same, so you have to make a decision and decide which one to redirect to the other.
personally if this was my solution I would'nt have a route for "~/Home" and my base node in my sitemap would look something like this:
It's clean and obvious that "http://yourdomain/" is the homepage and "http://yourdomain/Home" could be anything (about your home, my home, home sweet home, things i like in my home) whereas "http://adomain/" is the homepage across the globe for everyone.