Security trimming is not enabled by default. The first thing you need to do is enable it.
Internal DI (web.config):
<add key="MvcSiteMapProvider_SecurityTrimmingEnabled" value="true"/>
External DI (in the MvcSiteMapProvider module):
bool securityTrimmingEnabled = true; // First line in the module
Then you must put the MVC [Authorize] attribute for each of the action methods that you want to protect. In MVC4 +, you can also place it at the controller level or register it globally, and then use the [AllowAnonymous] attribute to selectively allow actions to methods allowed by unidentified users.
public class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new AuthorizeAttribute()); } } [Authorize(Roles="Admin,Manager")] public class MyController {
The role attribute in XML is intended for backward compatibility with ASP.NET. For MVC, the only real security is using the [Authorize] attribute (or inheriting it in your own way), because this is the only way to guarantee access to the resource through an alternative route.
source share