In Asp.net 2.0, different sitemaps are displayed based on roles.

Source: Internet
Author: User

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

.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.