Sitemap / Breadcrumb not displaying with Url routing on default page

I have setup web forms (4.0) using UrlRouting. My breadcrumbs appear when I go to

My main problem is http: // Localhost /

Since it is by default http: //Localhost/default.aspx in IIS

I am trying to avoid the route of adding another element to the sitemap XML file, for example

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

What is the best approach to use?

I tried adding this to my routing table and using xmlSiteMapProvider to see if I could do something with it (which didn't work).

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

Here are some details.

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 will see if I can manipulate routeCollection to somehow get a match.

+3
1

:

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", node Sitemap :

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

, "http://yourdomain/" , "http://yourdomain/Home" ( , , , , ), "http://adomain/" .

+1

Source: https://habr.com/ru/post/1774578/


All Articles