Sitecore 中有没有办法向用户无权访问的媒体库项目显示 link?

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

我想使用 Sitecore 安全性来访问站点上的某些文档需要 registration/login。但是,客户希望向匿名用户显示这些文档的链接,以此让他们知道,如果他们 register/login 那么他们将可以访问这些受保护的文档。

在 Sitecore 中有一些简单的方法可以做到这一点吗?我唯一能想到的就是使用某种安全禁用程序来获取文档列表并在页面上显示链接。

您可以使用 SecurityDisabler:

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

正如 Thomas Therkildsen 所建议的,您可以使用 Security Disabler,尽管 Sitecore 的首选方法是使用用户切换器。

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

SecurityDisabler 基本上赋予代码做任何它想做的事情的权利,而 UserSwitcher 更具限制性。

有关详细信息,请参阅 Security API cookbook