My goal is to programmatically activate a Web Application scoped feature. I'm running this code from a feature receiver of a Web scoped feature. I'm logged in as a Farm Administrator. My app pool account is the same account (also Farm Admin).
These two snippets don't work. In both cases, the SecurityException is thrown with a message "Access Denied."
//using{} omitted for brevity
public override void FeatureActivated(SPFeatureReceiverProperties properties) {
SPWeb web = properties.Feature.Parent as SPWeb;
web.Site.WebApplication.Features.Add( /*guid*/ ); //throws SecurityException
}
I also tried.
public override void FeatureActivated(SPFeatureReceiverProperties properties) {
SPWeb web = properties.Feature.Parent as SPWeb;
SPSecurity.RunWithElevatedPrivileges( () =>
{
SPSite elevatedSite = new SPSite(web.Site.ID);
elevatedSite.WebApplication.Features.Add( /*guid*/ ); //throws SecurityException
});
}
I don't understand why I would be getting this error if both the app pool acct and the current user are Farm Administrators. Please help.