Google Search

Google
 

Wednesday, May 28, 2008

How to 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>

1 comment:

Unknown said...


Given so much information in it. its very useful .perfect explanation about Dot net framework.Thanks for your valuable information. dot net training in chennai | best dot net training in chennai