C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






How to create Menu based on Sitemap and Roles


Posted Date: 23 May 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: KamalMember Level: Gold    
Rating: Points: 15



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>





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Menu  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Disable right mouse click Script
Previous Resource: How to get ASP.NET Page Name at Runtime
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use