Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I've created a custom timer job with the following sample

http://dotnetfinder.wordpress.com/2010/07/24/creatingcustomsharepointtimerjob2010/

The feature is site scoped. In the feature receiver on the FeatureActivated event I create the timer job and on the FeatureDeactivating event I delete the timer job.

The problem is that when I activate the feature with powershell everything is working fine but if I try to activate the feature in the browser it won't activate.

After a little debugging, I know it throws several security exceptions in the feature receiver. Is there a way to run the code with a higher privileged account, or should a feature that creates a timer job always be activated with powershell?

Thanks in advance! :)

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Several days ago I tried to run timer job in a feature receiver of web site. I was a farm administrator, but when I tried to run job, I alwas got an error. I investigated a lot of solutions and then asked this question. I think that is a good thread to undertsand how to configure timer job and place where this job should be run. I hope it will be helpful for you.

share|improve this answer
    
Thanks, now I understand why it is not possible (not without messing with the least privilege policy anyway) I'm going to activate it with powershell and mark the feature as hidden. –  Marlou Dec 6 '11 at 10:30

Yes, there is a method to run the code with a higher privileged account. Use the SPSecurity.RunwithElevatedPrivileges

This method runs under the Application Pool identity, which has site collection administrator privileges on all site collections hosted by that application pool.

Check the examples how it is used in the article.

share|improve this answer
    
Sorry I should said this in my post but I've already tried that, but the problem is that my application pool is not a farm administrator, so it has no rights to write to the configuration database –  Marlou Dec 2 '11 at 12:47
    
You mean that you have confirmed that by running the application pool with a farm admin account your feature can be activated from the web ui with no problem? –  SPArchaeologist Dec 2 '11 at 13:51
    
It would be good to analyse if you could post your code. –  Deepu Nair Dec 2 '11 at 16:47

Assuming that you are using SharePoint 2010, I suppose that you are begin blocked by the Remote Administration Access Denied setting. As from Msdn, this new security feature "explicitly blocks any modifications to the objects inheriting from SPPersistedObject in the Microsoft.SharePoint.Administration namespace and does not allow the content web applications to update the configuration database".

Since you are attempting to create a timer job from a site collection feature, the remote administration access denied setting will block the opeation and throw an Access Denied error.

If this is the case, you could try to change your feature scope to a web application level. In this case the feature will be activated in the central administration site, thus avoiding the Remote Administration setting.

You could also try to switch of the remote administration access denied feature, but I wouldn't recomand this.

You can find additional info about the issue in this kb article.

share|improve this answer
    
Thanks, I think it will work if I turn this off and make my applicationpool account a farm administrator account. However I think this isn't the right way, so I'm going to activate my feature with powershell, mark it as hidden. Anyway, thanks for helping me, my understanding of why it wasn't working is a lot better now. –  Marlou Dec 6 '11 at 10:35
    
Don't worry, my pleasure. Anyway... do you have any restriction that prevents you for changing the scope of the feature? A web-application level feature would be activated on the central administration site, thus avoiding the remote administration security setting. Anyway, similar question are common in this days... Alexander suggested link is probably one of the most complete topic. –  SPArchaeologist Dec 6 '11 at 10:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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