First, create the sitemap file, right-click project-> add new item, and select site map in the pop-up box. Then, select OK. Now the sitemap file is created.
Edit its content. The default content in the new sitemap file is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Sitemap xmlns = "http://schemas.microsoft.com/asp tutorial net/sitemap-file-1.042622>
<Sitemapnode url = "" title = "" description = ">
<Sitemapnode url = "" title = "" description = "/>
<Sitemapnode url = "" title = "" description = "/>
</Sitemapnode>
</Sitemap>
<Sitemapnode> attributes:
Url-link address
Title-displayed title
Description-description (tooltip)
Resourcekey-used for localization (enablelocalization = true must be added to the <sitemap> node)
Securitytrimmingenabled-whether to enable sitemap to support security features
Roles-which roles can access the current node and multiple roles are separated by commas (you need to set securitytrimmingenabled to true)
Sitemapfile-reference another sitemap File
Note: When the application permission is applied, the provider of the sitemap node in web. config must also have the corresponding configuration (securitytrimmingenabled = "true ")
Example:
<Sitemapnode url = "" title = "" description = "" roles = "administrator, manager, normaluser">
<Sitemapnode url = "~ /Admin/manageuser/manage_users.aspx "title =" manage users "description =" "roles =" administrator "/>
<Sitemapnode url = "~ /Admin/manage info/manage_mirrors.aspx "title =" manage hotels "description =" "roles =" manager "/>
<Sitemapnode url = "~ /Admin/regioninfo/region_list.aspx "title =" manage regions "description =" "roles =" administrator "/>
<Sitemapnode url = "~ /Admin/managetable/manage_selfdetails.aspx "title =" manage tables "description =" "roles =" normaluser "/>
Here, you need to set the roles, which can be set in web. config under each directory.
Configure sitemap in web. config,
<Sitemap defaultprovider = "sitemapprovider">
<Providers>
<Add name = "sitemapprovider"
Type = "system. web. xmlsitemapprovider"
Securitytrimmingenabled = "true"
Sitemapfile = "web. sitemap"/>
</Providers>
</Sitemap>
Finally, apply sitemap in masterpage,
<Asp: menu id = "menu1" runat = "server" performanceid = "sitemapdatasourcedefault" orientation = "horizontal">
<Staticmenuitemstyle forecolor = "white" itemspacing = "10px" font-underline = "false"/>
<Staticselectedstyle forecolor = "#99 ffff"/>
<Dynamicselectedstyle forecolor = "#99 ffff"/>
</Asp: menu>
<Asp: sitemapdatasource id = "sitemapdatasourcedefault" runat = "server" sitemapprovider = "sitemapprovider" showstartingnode = "false"/>