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:

    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;


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


1 Answer 1


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

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

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 that you have read and understand our privacy policy and code of conduct.

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