来自 SPWeb 的计时器作业

发布于 2024-08-31 05:24:27 字数 137 浏览 3 评论 0 原文

我想从代码中启动计时器作业需要农场管理员凭据。但是,我需要从将在任何网站中使用的 Web 部件启动计时器作业。现在,当我尝试启动作业时,它显然给了我一个访问被拒绝的错误,因为应用程序池身份不是场管理员。关于如何解决这个问题有什么想法吗?

谢谢,

I guess starting a timer job from within the code requires Farm admin credentials. However, I need to start a timer job from a web part that will be used in any site. Now when I try to start the job it gives me an access denied error obviously because the app pool identity is not farm admin. Any ideas on how to resolve this issue?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你是暖光i 2024-09-07 05:24:27

计时器作业以场管理员身份运行,并不打算由最终用户直接触发。由于某些作业可能是资源密集型的,因此只有场管理员才能创建新作业或修改现有作业的计划。

一种解决方案是使用 SPWorkItem< /a> 用于对用户任务进行排队的基础结构,然后由派生自 SPWorkItemJobDefinition。您的 Web 部件将调用 SPSite.AddWorkItem< /a> 添加工作项。当计时器作业运行时,它将查找具有匹配 WorkItemType GUID 的任何工作项并调用 ProcessWorkItem 重载。

Timer jobs run as the farm administrator and are not intended to be triggered directly by an end-user. Since some jobs may be resource intensive, only the farm admin can create new jobs or modify the schedule for existing jobs.

One solution is to use the SPWorkItem infrastructure to queue user tasks which are then processed by a custom timer job derived from SPWorkItemJobDefinition. Your webpart would call SPSite.AddWorkItem to add the work item. When your timer job runs, it will look for any work items with the matching WorkItemType GUID and invoke the ProcessWorkItem overload.

场罚期间 2024-09-07 05:24:27

你是对的。要启动计时器作业,应用程序池用户必须是场管理员。由于启动计时器作业需要您使用 SPSchedule 更新 SPJobDefinition 对象。 SPJobDefinition 是存储在 SharePoint 配置数据库中的 SPPersistedObject。只有场管理员才能写入此数据库。

我看不出有什么办法可以解决这个问题。

解决方法:
根据您的要求,您可以编写定期运行的主作业。此作业可以查询 SharePoint 列表并启动由此类列表项定义的另一个作业。由于主作业在场管理员帐户下运行,因此该作业将能够启动新的计时器作业。

Your are right. To start a timer job the app pool user has to be farm administrator. Since starting a timer job requires you to update a SPJobDefinition object with an SPSchedule. The SPJobDefinition is a SPPersistedObject which is stored in the SharePoint Config Database. Only farm administrators can write into this db.

I don't see a way to get pass this issue.

Workaround:
Depending on your requirements you could write a master job that runs on regular basis. This job could query a SharePoint list and start another job defined by such a list item. Since the master job runs under the Farm Administrator account, the job would be able to start a new timer job.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文