Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top