tags:

views:

38

answers:

1

I have sitemap which looks like this:

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

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
   <siteMapNode url="~/default.aspx" title="Prva stran" roles="*"  description="Shema ISEF">    
        <siteMapNode roles="2" title="Analize" id="Analize"  description="" >
             <siteMapNode url="~/karneki1.aspx" title="Karneki1"  description="" />
             <siteMapNode url="~/karneki2.aspx" title="Karneki2"  description="" />    
        </siteMapNode>
    </siteMapNode>
</siteMap>

if I set roles in a siteMapNode with title "Analiza" it works fine, the link is not shown in the navigation... but if I set roles on any of "karneki" siteMapNode the links are still visible...

Is it even posible to restrict access to lower links based on user role?

A: 

Use the SiteMap 'securityTrimmingEnabled' attribute:

http://msdn.microsoft.com/en-us/library/ms178428.aspx

The asecurityTrimmingEnabled attribute also needs to be added to the nodes in the markup:

http://weblogs.asp.net/jgalloway/archive/2008/01/26/asp-net-menu-and-sitemap-security-trimming-plus-a-trick-for-when-your-menu-and-security-don-t-match-up.aspx

An overview of how securityTrimmingEnabled is supposed to work:

http://blogs.msdn.com/b/dannychen/archive/2006/03/16/553005.aspx

IrishChieftain
It's already set to "true"
DiaMonD
<siteMap defaultProvider="XmlSiteMapProvider" enabled="true"> <providers> <clear /> <add name="XmlSiteMapProvider" description="Default SiteMap provider." type="System.Web.XmlSiteMapProvider " siteMapFile="Web.sitemap" securityTrimmingEnabled="true"/> </providers> </siteMap>
DiaMonD
I've updated the answer :-)
IrishChieftain
Exception Details: System.Configuration.ConfigurationErrorsException: Unrecognized attribute 'securityTrimmingEnabled'. Note that attribute names are case-sensitive.
DiaMonD
OK, i made some progress... roles only work if there is no url attribute in sitemapnode... any clues?
DiaMonD
What version of ASP.NET are you using? I remember having a problem with this before in 2.0. Eventually I had to programmatically add a "roles" attribute myself and tie it into my membership system. I had another attribute for "roletype" to distinguish between Active Directory and membership system. Wait a second... try making the "S" in 'securityTrimmingEnabled" capitalized? Let me know if that works first?
IrishChieftain
http://forums.asp.net/p/714465/714465.aspx
IrishChieftain
ASP.NET 2.0... I tried with capital S... it didn't show error but it didn't work ether. It still has problems with url=""... if it is not empty the roles don't work...
DiaMonD
is there any way to override this procedure, and to write my own conditions when will the link be shown or not?
DiaMonD
You've set up a membership system and have users and roles?
IrishChieftain
I set up my own role provider... anyway i gave up with these sitemap roles.. I wrote my own navigation control so now the roles work perfect. Sorry for wasting your time, and thank you for your help.
DiaMonD
No prob... I had to do the same thing some time back :-)
IrishChieftain