0

此代码是该行中的错误oJob.Update();

string JOB_NAME = "TestJob";
using (SPSite oSite = new SPSite("http://mysite", SPUserToken.SystemAccount))
{
NotifyJob oJob = new NotifyJob(JOB_NAME, oSite.WebApplication);
SPMinuteSchedule schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 30;
oJob.Schedule = schedule;
oSite.AllowUnsafeUpdates = true;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
oJob.Update();
});
oSite.AllowUnsafeUpdates = false;
}



Error: System.Security.SecurityException: Access denied.
 at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()
 at Microsoft.SharePoint.Administration.SPJobDefinition.Update()
4

2 回答 2

1

首先,请检查此解决方案是否适用于您的场景。从您的代码中,我猜您是从某种 webpart/page 执行它。

http://unclepaul84.blogspot.com/2010/06/sppersistedobject-xxxxxxxxxxx-could-not.html

第二件事是RunWithEvelatedPrivileges在应用程序池身份下执行代码。如果您从正常的 SharePoint 内容网站集执行它,该网站集在不同的应用程序池(和帐户 - 它应该如何)上运行,然后中央管理,您仍然可能无法访问需要农场管理员权限的计时器作业。

于 2012-10-30T08:59:11.973 回答
0

不要从 SPSite/SPWeb 构造函数获取站点或网站。你应该从 SPFeatureReceiverProperties 中获取它

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    SPWeb web = properties.Feature.Parent as SPWeb;
    NotifyJob oJob = new NotifyJob("TestJob", web.Site.WebApplication);
    SPMinuteSchedule schedule = new SPMinuteSchedule();
    schedule.BeginSecond = 0;
    schedule.EndSecond = 59;
    schedule.Interval = 30;
    oJob.Schedule = schedule;
    oJob.Update();
}

或者

SPSite site = properties.Feature.Parent as SPSite;

如果您的功能范围是站点

于 2012-10-30T09:50:37.950 回答