我正在尝试使用功能区按钮从列表中运行计时器作业,然后单击该按钮会弹出一个页面。在该页面加载上,我已赋予 runwithelevatedprivileges 和job.runnow()
. 我在生产环境中遇到拒绝访问异常,但在系统测试中运行良好。请参阅以下代码:
SPWebApplication mainWebApp = SPContext.Current.Site.WebApplication;
bool b = mainWebApp.RunningJobs.Cast<SPRunningJob>().Any(curRunningJob => curRunningJob
.JobDefinitionTitle.Equals("JobName"));
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPJobDefinition job = mainWebApp.JobDefinitions.Cast<SPJobDefinition>().
FirstOrDefault(i => i.DisplayName.Equals("JobName"));
SPContext.Current.Web.AllowUnsafeUpdates = true;
job.RunNow();//getting access denied exception at this line