ASP.NET2.0自動搜尋檔案組成導航系統

來源:互聯網
上載者:User
asp.net|導航

  ASP.NET2.0的導航系統確實給web開發帶來方便,但是用過的使用者就會發現導航系統有一個很大的缺陷:他需要你手工編寫web.sitemap,web.sitemap的文法用語句流行話是“相當的簡單”,但是實際運用時,雖然簡單,但是稍微複雜的導航,你肯定出錯。為什嗎?下面是一個簡單的sitemap,

<siteMap>
  <siteMapNode title="Home" url="~/default.aspx" >
    <siteMapNode title="Introduction to ASP.NET" url="~/introduction/default.aspx">
    <siteMapNode title="What's New in Whidbey?" url="~/introduction/whatsnew.aspx"/>
      <siteMapNode title="Sample Applications (Starter Kits)" url="~/introduction/starterkits.aspx"/>
      <siteMapNode title="Introduction to Visual Web Developer" url="~/introduction/vwd.aspx"/>
    </siteMapNode>
    <siteMapNode title="Building A Web Application" url="~/development/default.aspx">
      <siteMapNode title="Building a Simple Application" url="~/development/simple/default.aspx">
        <siteMapNode title="Introduction to ASP.NET pages" url="~/development/simple/pages.aspx"/>
        <siteMapNode title="Introduction to Server Controls" url="~/development/simple/servercontrols.aspx"/>
        <siteMapNode title="Inline vs Code Behind Pages" url="~/development/simple/codeseparation.aspx"/>
        <siteMapNode title="Sharing Code Between Pages" url="~/development/simple/codedirectory.aspx"/>
      </siteMapNode>
</siteMap>

    說白了,他只是一些siteMapNode 的嵌套,但是嵌套的開閉呼應對人而言,絕對是一個煩點,但是對電腦來說,就喜歡處理這些簡單的關係,所以我們可以編寫一個檔案,讓系統自動檢索當前應用程式的頁面並自動產生導航。

  miclae就寫了一篇文章,我已經將他用C#改寫並編譯為DLL檔案,現在 你只要把該DLL檔案拷貝到你項目的bin目錄下。並設定導航控制項(menu,treeview)為引用該DLL,運行時,系統將自動根據你的目錄檔案自動產生導航系統。

  當然,該DLL檔案的功能遠遠不只這些,他會自動去掉APP_*和bin目錄,如果你願意,你完全可以在web.config裡配製他,告訴dll 不要把某個目錄進行現實等。

  現在你在添加/刪除檔案時,再也不用修改web.sitemap



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.