Use the WebConfigModifications property of the SPWebApplication or SPWebService class to get the collection of web.config modifications either in the Web application or in all Web applications within the Web service.
Here's a console app as POC.
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
class Program {
private const string ScriptResourceHandler = @"<add verb=""GET,HEAD"" path=""FOO.bar"" type=""System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions"" validate=""false""/>"
static void Main(string[] args)
{
SPSite siteCollection = new SPSite("http://localhost");
SPWebApplication webApp = siteCollection.WebApplication;
SPWebConfigModification modification = new SPWebConfigModification();
modification.Path = "configuration/system.web/httpHandlers"
modification.Name = "Example"
modification.Value = value;
modification.Owner = "ExampleOwner"
modification.Sequence = 0;
modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
webApp.WebConfigModifications.Add(modification);
// .Remove doesn't remove it from the web.config, BTW... :(
webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
}
}
No comments :
Post a Comment