如何连接到sitecore中的核心数据库

Raj*_*esh 2 c# asp.net sitecore

如何连接到sitecore中的核心数据库如何从sitecore中的核心数据库获取项目的值.

Sitecore.Data.Database coredb = Sitecore.Configuration.Factory.GetDatabase("core");
Run Code Online (Sandbox Code Playgroud)

我正在使用上面提到的代码,但我无法得到这些值

Jan*_*ink 6

Sitecore核心数据库中的项目对所有用户都不可读,匿名用户在核心数据库中默认没有读取权限.使用Access Viewer检查所需项目的"读取"权限.

我认为您需要在代码或UserSwitcher中使用SecurityDisabler或提供读取权限.

这将有效:

using Sitecore.SecurityModel;

.....


Sitecore.Data.Database coredb = Sitecore.Configuration.Factory.GetDatabase("core");

using (new SecurityDisabler())
{
  var a = coredb.GetItem("/sitecore");
}
Run Code Online (Sandbox Code Playgroud)

  • 我建议不要将SecurityDisabler()用于实际网站,除非你知道你正在做什么的含义.最安全的方法是使用UserSwitcher在具有执行操作所需的最小权限**的帐户上运行命令. (2认同)