In the Web. sitemap file, the sitemapnode node has the roles attribute, but direct setting does not work. After verifying the information, you must set it in the web. config file.Site Map providers.
< System . Web >
...
< Sitemap Defaultprovider = "Xmlsitemapprovider" Enabled = "True" >
< Providers >
< Add Name = "Xmlsitemapprovider"
Description = "Sitemap provider which reads in. sitemap XML files ."
Type = "System. Web. xmlsitemapprovider, system. Web, version = 2.0.0.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a"
Sitemapfile = "Web. sitemap"
Securitytrimmingenabled = "True" />
</ Providers >
</ Sitemap >
</ System. Web >
Note that in the sitemap section, the key is the settings here, and then the correspondingSitemapnodeAddRolesAttribute. However, in actual application, it can only be added to the first-level node, and the second-level node is invalid, as shown in the following example.
<? XML version = "1.0" encoding = "UTF-8" ?>
< Sitemap Xmlns = "Http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
< Sitemapnode URL = "" Title = "System Management" Description = "" Roles = "System management account, user administrator" >
< Sitemapnode URL = "~ /System/usermanage. aspx" Title = "User Management" Description = "" />
< Sitemapnode URL = "~ /System/createuser. aspx" Title = "Create user" Description = "" />
< Sitemapnode URL = "~ /System/citymanage. aspx" Title = "City Maintenance" Description = "" />
</ Sitemapnode >
</ Sitemap >
In addition, you can use the msdn query.Site Map providersYou can connect to the database to read sitemap
First, you must use sitemapapi as a custom provider.
It uses a stored procedure.
Create Procedure Proc_getsitemap As Select [ ID ] , [ Title ] , [ Description ] , [ URL ] , [ Roles ] , [ Parent ] From [ Sitemap ] Order By [ ID ]
Then make the following settings in Web. config:
< Configuration >
< Connectionstrings >
< Add Name = "Sitemapconnectionstring" Connectionstring = "..." />
</ Connectionstrings >
< System . Web >
< Sitemap Enabled = "True" Defaultprovider = "Aspnetsqlsitemapprovider" >
< Providers >
< Add Name = "Aspnetsqlsitemapprovider"
Type = "Sqlsitemapprovider, customproviders"
Description = "SQL server site map provider"
Securitytrimmingenabled = "True"
Connectionstringname = "Sitemapconnectionstring"
/>
</ Providers >
</ Sitemap >
</ System. Web >
</ Configuration >
Database sitemap table structure
Create Table [ DBO ] . [ Sitemap ] (
[ ID ] [ Int ] Not Null ,
[ Title ] [ Varchar ] ( 32 ),
[ Description ] [ Varchar ] ( 512 ),
[ URL ] [ Varchar ] ( 512 ),
[ Roles ] [ Varchar ] ( 512 ),
[ Parent ] [ Int ]
) On [ Primary ]
Go
Alter Table [ DBO ] . [ Sitemap ] Add
Constraint [ Pk_sitemap ] Primary Key Clustered
(
[ ID ]
) On [ Primary ]
Go
Data instance
On msdnSite Map providersAddress: http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/dnaspp/html/aspnetprovmod_prt3.asp
.