2010-11-12 118 views
3

我已經使用UrlRouting設置了我的Web表單站點(4.0)。當我去Sitemap/Breadcrumb在默認頁面上沒有顯示Url路由

我的主要問題是與http://Localhost/

,因爲它默認爲http://Localhost/default.aspx在IIS

我 出現在我的麪包屑試圖避免向站點地圖添加另一個元素的路線xml like

<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獲得比賽莫名其妙。

回答

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> 

否則 「〜/」 和 「〜/家庭」 是同一回事。

,或者你可以離開這個上面是在Default.aspx頁面做這樣的事......

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

這將有效地重定向任何默認請求到您的默認請求。

您的問題是服務器將〜/「和」〜/ Home「視爲2個不同的URL,您基本上希望它們相同,因此您必須作出決定並決定將哪一個重定向到。其他

個人,如果這是我的解決方案我would'nt有一個路線「〜/家」,並在我的地圖我的基本節點會是這個樣子:

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

很乾淨,很明顯, 「http:// yourdomain /」是首頁,「http:// yourdomain/Home」可以是任何東西(關於你的家,我的家,家裏的甜蜜的家,我喜歡在家裏的東西),而「http:// adomain /「是全球每個人的主頁。

+0

感謝沃迪的回答。我將不得不回到這個代碼的東西的擺動。有一陣子了。我試圖把你的url =「〜/」title =「home」放到我的站點地圖中,但無濟於事。當我去Http:// yourdomain時,麪包屑不會出現。 – Lareau 2011-07-11 19:14:37

+0

你期待在麪包屑中看到什麼? ...對於一個主頁技術上沒有面包屑,因爲麪包屑從當前位置顯示回到根的路徑,因此主頁是一種例外......我傾向於硬編碼鏈接到〜/ if我覺得它的相關...事情是...如果你在網頁上,爲什麼你會顯示一個鏈接到主頁? – War 2011-07-12 08:41:05

+0

好點,我總是假設,如果你在主頁上,它會說首頁,但沒有鏈接。從我的快速谷歌搜索,人們只是從主頁中刪除它。感謝您的提示 – Lareau 2011-07-12 10:54:44