asp.net2.0的導航系統確實給帶來方便,但是用過的用戶就會發現導航系統有一個很大的缺陷:他需要你手工編寫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
新聞熱點
疑難解答
圖片精選