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

まず、このソリューションがあなたのシナリオに当てはまるかどうかを確認してください。あなたのコードから、ある種のWebパーツ/ページから実行していると推測しています。

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

2 つ目は、RunWithEvelatedPrivilegesアプリケーション プール ID の下でコードを実行することです。サーバーの全体管理とは異なるアプリ プール (およびアカウント - どのようにすべきか) で実行されている通常の SharePoint コンテンツ サイト コレクションから実行している場合でも、ファーム管理者権限が必要なタイマー ジョブにアクセスできない可能性があります。

于 2012-10-30T08:59:11.973 に答える
0

SPSite/SPWeb コンストラクターからサイトまたは Web を取得しないでください。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 に答える