使用 SPWebConfigModification:
http://spmatt.wordpress.com/2013/05/22/using-spwebconfigmodification-to-update-the-web-config-in-sharepoint-2013/
在你的情况下,你会有一些类似的东西:
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);
您可能需要调整 Xpath,因为我不确定该元素在 web.config 中的位置
您应该在功能接收器中使用它,您可以在其中获取对您的 Web 应用程序的引用,并且您应该始终在功能停用时删除它们