Set Your Web Site's Navigation Structure Easily with ASP.NET 2.0 Site Maps, Page 3
Now, you need to configure the site map provider and enable security trimming so that the SiteMap data source control can do what you require from it. Add the following markup to the web.config file:
<siteMap defaultProvider="myprovider" enabled="true"> <providers> <add name="myprovider" type="System.Web.XmlSiteMapProvider " siteMapFile="SecurityTrimming.sitemap" securityTrimmingEnabled="true" /> </providers>
Here, you added the <siteMap> section and specified a provider pointing to the SecurityTrimming.sitemap file. Note that the securityTrimmingEnabled attribute is set to true to enable security trimming. After you configure the <siteMap> section, the SiteMap data source control automatically picks up the setting from this section.
Run Login.aspx (see Figure 11) and enter the credentials for user1.
Figure 11: Login Page
After you log in successfully, you should see the TreeView as shown in Figure 12. Because user1 belongs to the ProductTesters role, the service-related links are hidden.
Figure 12: Security Trimming in Action
What Have You Learned?
Site map is an XML file that details the structure of your Web site. You can consume the site map file to generate navigation structures. The three common ways to consume site map files are by using the SiteMapPath control, the SiteMap data source control, or the SiteMap class. You also can use a feature called security trimming to enable role-based security to the navigation links rendered. These controls and classes together help you create a professional navigation structure for your Web sites.
Download the Code
Download the code that accompanies the examples in this article.
About the Author
Bipin Joshi is the founder and owner of BinaryIntellect Consulting, where he conducts professional training programs on .NET technologies. He is the author of Developer's Guide to ASP.NET 2.0 and co-author of three WROX press books on .NET 1.x. He also is a Microsoft MVP, member of ASPInsiders, MCAD, and MCT.
Page 3 of 3