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

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.

share|improve this question

1 Answer 1

So you're trying to activate an application wide feature from within a single collection? I've never tried this, but I'm wondering if SharePoint would even let you do it since potentially a user in one isolated collection could effect all users in any collection of that app. It may only let you "manage" objects at the current level and below. Do you have any other error trapping beyond what SharePoint is dumping out by default?

share|improve this answer
    
I'd agree that this may be the problem. It sort of makes sense. You may try working around it by activating the feature separately, then determining in this code whether it is activated, failing if not with some message about contacting your system admin. –  Mike H Jun 11 '10 at 4:07

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.