gpt4 book ai didi

Sitecore 计划任务 : Cannot access any items in run class

转载 作者:行者123 更新时间:2023-12-02 00:45:49 25 4
gpt4 key购买 nike

我通过数据库配置了一个计划任务,该任务按预期触发并调用 C# 类中的“Execute”方法。我的问题是在我的 Execute 方法中无法访问 Sitecore 项目。我什至在调用 Sitecore.Context.Database 时得到 NullPointerExecption。

我想这一定是一个安全问题,这是有道理的。所以我尝试使用 UserSwitcher 和 SecurityDisabler 获取权限,但这没有帮助。

任何人都可以指出我所缺少的吗?

最佳答案

您不能在计划任务中使用 Sitecore.Context。它在那里不存在。 Sitecore.Context绑定(bind)HttpRequest,定时任务中没有请求。正如 John W 在他的文章 (The Sitecore Context) 中所写:

The Sitecore context, exposed by the static Sitecore.Context class, contains information about the Sitecore installation and the current HTTP request. Processors in the httpRequestBegin pipeline defined in the web.config file are largely responsible for defining the Sitecore context. After Sitecore determines the context database, it determines the context item in that database.

在调度作业中,您应该通过名称获取数据库,例如:

var masterDb = Sitecore.Data.Database.GetDatabase("master");
var webDb = Sitecore.Data.Database.GetDatabase("web");

关于Sitecore 计划任务 : Cannot access any items in run class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43967421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com