I have a web application in ASP.NET, which has a site map.
One of these menu items must be displayed only, if the user is assigned role roleX
.
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<siteMapNode url="~/" title="Root" description="...">
<siteMapNode url="" title="Menu 1" description="" roles="*">
<siteMapNode url="~/Default.aspx" title="Item 1" description="" roles="*"/>
<siteMapNode url="~/rss.aspx" title="Subscription" description="" roles="*" />
</siteMapNode>
<siteMapNode url="~/specialPage.aspx"
title="Some special page"
description=""
roles="roleX"/>
</siteMapNode>
</siteMap>
In my web.config
I've setup the site map and the role provider like this:
<connectionStrings>
<add name="dbConnectionString" connectionString="Data Source=MY-MACHINE\SQLEXPRESS;Initial Catalog=MyDatabase;Persist Security Info=True;Integrated Security=SSPI" providerName="System.Data.SqlClient"/>
</connectionStrings>
...
<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
<providers>
<add name="XmlSiteMapProvider"
description="Default SiteMap provider."
type="System.Web.XmlSiteMapProvider "
siteMapFile="Web.sitemap"
securityTrimmingEnabled="true"/>
</providers>
</siteMap>
<roleManager
defaultProvider="SqlProvider"
enabled="true"
cacheRolesInCookie="false"
cookieName=".ASPROLES"
cookieTimeout="30"
cookiePath="/"
cookieSlidingExpiration="true"
cookieProtection="All">
<providers>
<clear/>
<add
name="SqlProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="dbConnectionString"
applicationName="MyApp" />
</providers>
</roleManager>
There are tables
aspnet_Applications
aspnet_Membership
aspnet_Paths
aspnet_PersonalizationAllUsers
aspnet_PersonalizationPerUser
aspnet_Profile
aspnet_Roles
aspnet_SchemaVersions
aspnet_Users
aspnet_UsersInRoles
aspnet_WebEvent_Events
in the database MyDatabase
.
There are no records in the aspnet_UsersInRoles
table.
So, when I launch the web application, the menu item (site map node) specialPage.aspx
should not be visible (because no user is assigne the role roleX
).
But it is displayed nevertheless.
2 questions:
- Why?
- What can I do in order for the menu item
specialPage.aspx
to be visible only, if the user is assigned the roleroleX
?