1

While i'm tring to install a TimerJob with the event reciever, i get this error:

An exception of type 'System.Security.SecurityException' occurred in Microsoft.SharePoint.dll but was not handled in user code Additional information: Access denied.

I even cheked the trust level on my webconfig and its 'Full'. The featue also runed with a fram account . the scope is web.

here is the code :

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try
            {
                SPWeb web = properties.Feature.Parent as SPWeb;

                SPSite site = web.Site as SPSite;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite elevatedSite = new SPSite(site.ID))
                    {
                        // make sure the job isn't already registered   
                        foreach (SPJobDefinition job in elevatedSite.WebApplication.JobDefinitions)
                        {
                            if (job.Name == "aaa")
                            {
                                job.Delete();
                                break;
                            }
                        }
                        // install the job   
                        SITEP_DataBaseSynchronisation.TimerJob.SITEP_DataBaseSynchronisation_TimerJob corpProfileJob = new SITEP_DataBaseSynchronisation.TimerJob.SITEP_DataBaseSynchronisation_TimerJob("aaa", site.WebApplication);

                        corpProfileJob.Properties.Add("WebName", web.ServerRelativeUrl);
                        corpProfileJob.Properties.Add("WebURL", web.Url);
                        corpProfileJob.Properties.Add("Web", web.ID.ToString());
                        corpProfileJob.Properties.Add("Site", web.Site.ID.ToString());

                        // Updates the timer schedule values   
                        //SPDailySchedule schedule = new SPDailySchedule();
                        //schedule.BeginHour = 18;
                        //schedule.EndHour = 19;
                        //schedule.BeginMinute = 58;
                        //schedule.EndMinute = 00;
                        //schedule.BeginSecond = 0;
                        //schedule.EndSecond = 0;
                        SPMinuteSchedule schedule = new SPMinuteSchedule();
                        schedule.BeginSecond = 0;
                        schedule.EndSecond = 59;
                        schedule.Interval = 15;                  
                        corpProfileJob.Schedule = schedule;
                        corpProfileJob.Update();
                        elevatedSite.WebApplication.JobDefinitions.Add(corpProfileJob);
                    }
                });
            }
            catch (Exception ex) { }  
        }
1

In your timer job cs file override HasAdditionalUpdateAccess

protected override bool HasAdditionalUpdateAccess()
{
    return true;
}

Also try activating feature via SharePoint Management Shell.

0

My guess would be that the Application Pool Account, doesn't have permission to add/delete jobs to/from the WebApplication. So if you're always activating the feature using the Farm account try remove the RunWithElevatedPrivileges

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.