站点地图/面包屑未在默认页面上显示 URL 路由

发布于 2024-10-01 15:36:24 字数 2584 浏览 0 评论 0 原文

我已经使用 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 以某种方式获得匹配。

I've got my web forms site (4.0) setup with UrlRouting.
My bread crumb appears when I go to

My main issue is with http://Localhost/

Since it's defaulting to http://Localhost/default.aspx in IIS

I'm trying to avoid the route of adding another element to the sitemap xml like

<siteMapNode url="~/Home" title="Home"  description="Home" aspx="default.aspx">

What would be the best approach to use?

I've tried to add this to my routing table & using an xmlSiteMapProvider to see if I could so something with it (which didn't work).

routes.MapPageRoute("IISDefault", "", "~/Default.aspx");

Here's some of info.

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;

    }

Edit: I'm going to see if I can manipulate the routeCollection to get a match somehow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎樣才叫好 2024-10-08 15:36:24

而不是:

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>

尝试这个:

Routes
routes.MapPageRoute("Default", "Home", "~/");
routes.MapPageRoute("ListAll", "List", "~/ListAll.aspx");

Sitemap
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="~/" title="Home"  description="Home">
        <siteMapNode url="~/List" title="List All"  description="List All"  />
    </siteMapNode>
</siteMap>

否则“~/”和“~/Home”是同一件事。

或者您可以按原样保留上述内容,并在 default.aspx 页面中执行类似以下操作...

if(Page.RouteData.Values[0] == "default.aspx")
    Response.Redirect("~/Home")

这将有效地将任何默认请求重定向到您的默认请求。

您的问题是服务器将 ~/" 和 "~/Home" 视为 2 个不同的 url,而您基本上希望它们相同,因此您必须做出决定并决定将哪一个重定向到另一个。

就个人而言,如果这是我的解决方案,我不会有“~/Home”的路线,并且站点地图中的基本节点看起来像这样:

<siteMapNode url="~/" title="Home"  description="Home">

“http://yourdomain/”是主页,“http:”是干净且明显的。 //yourdomain/Home”可以是任何东西(关于你的家、我的家、甜蜜的家、我喜欢的东西),而“http://adomain/”是全球每个人的主页。

Instead of :

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>

try this:

Routes
routes.MapPageRoute("Default", "Home", "~/");
routes.MapPageRoute("ListAll", "List", "~/ListAll.aspx");

Sitemap
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="~/" title="Home"  description="Home">
        <siteMapNode url="~/List" title="List All"  description="List All"  />
    </siteMapNode>
</siteMap>

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 ...

if(Page.RouteData.Values[0] == "default.aspx")
    Response.Redirect("~/Home")

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:

<siteMapNode url="~/" title="Home"  description="Home">

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文