Tutorials and code for ASP.NET 2.0,C#,SQL Server,AJAX tutorials,jQuery  
Home    Articles    Contact Us
 

ASP.NET
AJAX
Interview Questions
Sql Server
Technology News
Tips and Tricks
jQuery

 

Create Menu based on Sitemap and Roles


The following code sample shows how to create Menu based on Sitemap and Roles.

The combination of ASP.NET role management and ASP.NET URL authorization provide
a way to restrict access to Web files based on security roles.

Security trimming is a very cool feature which allows you to hide the urls based
on the users roles.

First create Web.sitemap in website also add roles for access url.

<?xml version="1.0" encoding="utf-8" ?>

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/Default.aspx" title="Home" description="Home">
<siteMapNode url="~/contactus.aspx" title="Contact US" description="Contact US" />
<siteMapNode url="~/aboutus.aspx" title="About Us" description="About Us" roles="*"/>
<siteMapNode url="~/articles.aspx" title="Articles" description="Articles"/>
<siteMapNode url="~/admin.aspx" title="Admin" description="Articles" roles="Admin"/>
</siteMapNode>
</siteMap>

In above site admin.aspx is display only to person who has Admin role.and roles
"*" means display for everyone.

Now,define sitemap providers in web.config file and enable security trimming

(securityTrimmingEnabled is set to true ).

<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
<providers> <add name="UserMenuSiteMap" description="Used for Menu"
type="System.Web.XmlSiteMapProvider" siteMapFile="Web.siteMap" securityTrimmingEnabled="true"/>
</providers>
</siteMap>


User Comments:




Post Your Comment :


Name
Email:
Comment:

Home | Contact Us

© 2008-09 TechnoReader.com. All rights reserved.