Create a sitemap sml based file and save it with sitemap.config name. Here is an example.
- <?xml version="1.0" encoding="utf-8" ?>
- <siteMap>
- <siteMapNode title="Home" controller="Home" action="Overview">
- <siteMapNode title="Dashboard" nopResource="Admin.Dashboard" controller="Home" action="Index" ImageUrl="~/Administration/Content/images/ico-dashboard.png" />
- <siteMapNode title="Catalog" nopResource="Admin.Catalog" PermissionNames="ManageCatalog" ImageUrl="~/Administration/Content/images/ico-catalog.png" >
- <siteMapNode title="Categories" nopResource="Admin.Catalog.Categories">
- <siteMapNode title="List" nopResource="Admin.Common.List" controller="Category" action="List"/>
- <siteMapNode title="Tree view" nopResource="Admin.Common.Treeview" controller="Category" action="Tree"/>
- </siteMapNode>
- </siteMap>
If you're new to sitemap, learn here
how to create a site map in Visual Studio.
To bind above sitemap and display on a page, please follow the below code example.
- @using System.Data;
- @using System;
- <div class="page-title">
- <h2>"Sitemap"</h2>
- </div>
- @{
- string fileName = System.Web.HttpContext.Current.Server.MapPath("~/sitemap.config");
- DataSet ds = new DataSet();
- ds.ReadXml(fileName);
- <table>
- <tr>
- <td width="20%"></td>
- <td style="border: 2px double #CCCCCC; padding-left: 50px;" width="30%">
- @for(int i=1;i<ds.Tables[0].Rows.Count/2;i++)
- {
- if(ds.Tables[0].Rows[i]["action"].ToString()=="")
- {
- <h4>@ds.Tables[0].Rows[i]["title"].ToString()</h4>
- }
- else
- {
- string url = "../" + @ds.Tables[0].Rows[i]["controller"].ToString() + "/" + @ds.Tables[0].Rows[i]["action"].ToString();
- <ul class="top-menu"><li><a href="@url" temp_href="@url">@ds.Tables[0].Rows[i]["title"].ToString()</a></li></ul>
- }
- }
- </td>
- <td style="border: 2px double #CCCCCC; padding-left: 50px;" width="30%">
- @for (int i = ds.Tables[0].Rows.Count / 2; i < ds.Tables[0].Rows.Count; i++)
- {
- if(ds.Tables[0].Rows[i]["action"].ToString()=="")
- {
- <h4>@ds.Tables[0].Rows[i]["title"].ToString()</h4>
- }
- else
- {
- string url = "../" + @ds.Tables[0].Rows[i]["controller"].ToString() + "/" + @ds.Tables[0].Rows[i]["action"].ToString();
- <ul class="top-menu"><li><a href="@url" temp_href="@url">@ds.Tables[0].Rows[i]["title"].ToString()</a></li></ul>
- }
- }
- </td>
- </tr>
- </table>
- }
Run application and you'll see a page with sitemap links.