1

I have an application page under _layouts, and in it I am trying to do a web.config modification. The page inherits from LayoutsPageBase. The code inside the event handler looks like this:

SPSecurity.RunWithElevatedPrivileges(delegate
{
    using (var site = new SPSite(siteId))
    {
        var webApp = site.WebApplication;
        var modification = new SPWebConfigModification();
        modification.Name = @"add[@key=""MyKey""]";
        modification.Path = "configuration/appSettings";
        modification.Value = @"<add key=""MyKey"" value=""MyValue"" />";
        modification.Owner = this.Context.User.Identity.Name;
        modification.Sequence = 0;
        modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

        webApp.WebConfigModifications.Add(modification);
        webApp.WebService.ApplyWebConfigModifications();
        webApp.Update();
    }
});

However, I always get an exception, even when the user that I am using is a farm administrator! What am I doing wrong?

2

1 Answer 1

0

I found out. I had to do this in PowerShell:

$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$contentService.RemoteAdministratorAccessDenied = $false
$contentService.Update()

Couldn't do it in the application page, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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