Skip to content
Maarten Balliauw
← back
ASP.NET 1 min read

Enable sitemap security trimming in ASP.NET 2.0

edit this page

Want to enable security trimming for your ASP.NET sitemap? Here’s how…

First of all, you need a new section in your web.config system.web element:

xml
<system.web>
  <!-- ... other system.web configuration stuff ... -->
  <siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
    <providers>
      <add name="XmlSiteMapProvider"
        description="Default SiteMap provider."
        type="System.Web.XmlSiteMapProvider "
        siteMapFile="Web.sitemap"
        securityTrimmingEnabled="true" />
    </providers>
  </siteMap>
</system.web>

Next, you should specify which pages are visible to who:

xml
<location path="ForgotPassword.aspx">
  <system.web>
    <authorization>
      <allow users="?"/>
      <deny users="*"/>
    </authorization>
  </system.web>
</location>
<location path="ModifyPassword.aspx">
  <system.web>
    <authorization>
      <deny users="?"/>
      <allow users="*"/>
    </authorization>
  </system.web>
</location>

In this example, the page ForgotPassword.aspx is visible to anonymous users, while authenticated users do not need this page (as they already knew their password while logging in…). ModifyPassword.aspx is only visible to authenticated users, as anonymous users can’t do that.

Maarten Balliauw

Writing about .NET, web, performance and security, since 2006.

Related posts

★ Prefer this blog on Google