如何在SharePoint中将节添加到web配置中

如何在SharePoint中将节添加到web配置中,sharepoint,sharepoint-2010,web-config,webconfigurationmanager,Sharepoint,Sharepoint 2010,Web Config,Webconfigurationmanager,我在SharePoint的web配置中有很多自定义条目。 有没有一种方法可以通过编程来实现呢。 像我这样 这要在下面添加 <PageParserPath> <PageParserPath VirtualPath="/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" /> 此外,我还有一个完整的新部分要添加称为 <connectionst

我在SharePoint的web配置中有很多自定义条目。 有没有一种方法可以通过编程来实现呢。 像我这样 这要在下面添加

 <PageParserPath>
<PageParserPath VirtualPath="/*" CompilationMode="Always" AllowServerSideScript="true"      IncludeSubFolders="true" />

此外,我还有一个完整的新部分要添加称为

<connectionstring>
entries here
</connectionstring>

这里的条目

如何通过编程实现任何想法请使用SPWebConfigModification:

在你的情况下,你会有以下几点:

        var httpRuntimeModification = new SPWebConfigModification();
        httpRuntimeModification.Path = "configuration/PageParserPath";
        httpRuntimeModification.Name = "myModification";
        httpRuntimeModification.Sequence = 0;
        httpRuntimeModification.Owner = "MyAppName";
        httpRuntimeModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNodes;
        httpRuntimeModification.Value = "<PageParserPath VirtualPath='/*' CompilationMode='Always' AllowServerSideScript='true'      IncludeSubFolders='true' />";
        webApp.WebConfigModifications.Add(httpRuntimeModification);
var httpRuntimeModification=new SPWebConfigModification();
httpRuntimeModification.Path=“配置/PageParserPath”;
httpRuntimeModification.Name=“myModification”;
httpRuntimeModification.Sequence=0;
httpRuntimeModification.Owner=“MyAppName”;
httpRuntimeModification.Type=SPWebConfigModification.SPWebConfigModificationType.EnsureChildNodes;
httpRuntimeModification.Value=“”;
webApp.WebConfigModifications.Add(httpRuntimeModification);
您可能需要调整Xpath,因为我不确定该元素在web.config中的位置

您应该在功能接收器中使用它,在那里您可以获得对您的Web应用程序的引用,并且应该在功能停用时始终删除它们