这两天做了一个SharePoint的timerjob 我在激活feature的时候报了权限错误,一直是拒接访问。
代码中我已近提权了,并且所用的账号都是管理员账号登陆SharePoint的 。
代码:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
const string _MYNAME = "SendMailTimeJob";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite site = properties.Feature.Parent as SPSite;
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
{
if (job.Name == _MYNAME)
{
job.Delete();
}
}
SendTimeJob eventime = new SendTimeJob(_MYNAME, site.WebApplication);
SPMinuteSchedule _SpMs = new SPMinuteSchedule();
_SpMs.BeginSecond = 0;
_SpMs.EndSecond = 59;
_SpMs.Interval = 1;
eventime.Schedule = _SpMs;
eventime.Update();
});
}
求教。。。
sharepoint timejob?计时器任务
------解决方案--------------------
之前有个老外给了两种解决方案 我用的其中一种 增加下面的代码到job的定义
protected override bool HasAdditionalUpdateAccess()
{
return true;
}