Could you help me understand the SharePoint timer job?
The issue is simple. I should implement a page and put it to the layout folder (the page should be accessible from any web). This page should contain a button that adds a new job to the job definitions on the web application. Is it pretty simple? I don't think so...
When I tries to invoke job.Update()
methods under my account or run this method under SPSecurity.RunWithElevatedPrivileges
delegate I have got an Access Denied exception.
I found this post. Sean McDonough said
When a timer job instance is created, it is persisted to the farm configuration database. Accessing this database for write purposes is a privileged operation; as a rule of thumb, only the farm service account (that is, the account under which OWSTIMER.EXE executes) or accounts that explicitly have the rights required to carry out such an operation on the config database (typically administrators) will succeed.
I opened services and looked at the account under which OWSTIMER.EXE executes. It is a Network Services. I should be happy because my application pool uses the same account and I can use SPSecurity.RunWithElevatedPrivileges
. But I'm not. I still have an access denied exception.
Next... I look at my account. My accout is a member of Farm administrator group. I can manage timer jobs on the configuration page in CA. I can do everything with any job. But it is only in CA. If I try to invoke job.Update()
method on any other web I have access denied exception.
Sean also said
Timer job instances are typically created at Feature activation time in Features scoped at either the Farm or WebApplication level. Why? Because those Features are normally activated by administrators from either the command line (assuming the admin also has rights in the farm config database) or from within Central Administration.
I know that this solution works. I think that if I inherite my page from GlobalAdminPageBase and use it thru CA it will work too...
But is it possible to configure SharePoint to run timer job from page that is accessible from any web?
Why does not SPSecurity.RunWithElevatedPrivileges
work in my case? Why don't I run job under my credentials?