Martin Davies
Martin Davies

Reputation: 4456

Sitecore - Prevent access to a page, but still show it in the navigation

In Sitecore I have denied access to a particular page for the anonymous user.

This works correctly, but it also means that the page does not appear in the navigation menus and sitemap (both XSLT).

What I would like is for the user to be able to see the link, but be redirected to a Register/Login page when they click on it.

Upvotes: 2

Views: 1025

Answers (2)

Andy Uzick
Andy Uzick

Reputation: 81

You could wrap the rendering logic in the menus in a SecurityDisabler, so it would render all item links, even if the user "cant see" them.

using (SecurityDisabler disabler = new SecurityDisabler())
{
  foreach (Item item in Sitecore.Context.Item.Children)
  {
    ... render the link ...
  }
}

Upvotes: 3

Wesley Lomax
Wesley Lomax

Reputation: 2077

You'd need to allow anonymous users to view the page for it to be visible in the menu and sitemap.

What you could do though is override the Sitecore.Pipelines.HttpRequest.HttpRequestProcessor to check if the page requires a login (by adding a RequiresLogin True/False to the template for example), then check if the user is logged in if not redirect to your login page.

Theres an example of overriding the HttpRequestProcessor here

Upvotes: 3

Related Questions