Corey Burnett
Corey Burnett

Reputation: 7340

Is there a way in Sitecore to display a link to a media library item that the user does not have access to?

I want to use Sitecore security to make access to certain documents on a site require registration/login. However the client would like to show links to these documents to anonymous users as a way to let them know that if they register/login then they will get access to these protected documents.

Is there some simple way to do this in Sitecore? The only thing I can think of off the top of my head is to use some sort of Security Disabler to get the list of documents and display the links on the page.

Upvotes: 2

Views: 264

Answers (2)

Thomas Therkildsen
Thomas Therkildsen

Reputation: 150

You could use the SecurityDisabler:

using (new SecurityDisabler())
{
    //code to get links
}

Upvotes: 0

Martin Davies
Martin Davies

Reputation: 4456

As Thomas Therkildsen suggests, you can use the Security Disabler, although Sitecore's preferred method is to use a user switcher.

using (new Sitecore.Security.Accounts.UserSwitcher(userWithMoreRights))
{
    // ...
}

SecurityDisabler basically gives the code the right to do anything it wants, whereas UserSwitcher is more restrictive.

See the Security API cookbook for more information.

Upvotes: 1

Related Questions