MSDN上写的不是很明白,自己测试通过,记录一下:
方法一:通过创建描述一组 Web.config 修改的 XML 文件以声明方式注册 Web.config 项。
备注:
直接写一个webconfig.**.xml到14文件夹下的CONFIG中,在运行stsadm -o copyappbincontent 效果是一样的;
方法一有个缺点,会把所有WebApplication的web.Config都修改掉;
1.在sharepoint解决方案里添加14文件夹下的CONFIG文件夹,新建webconfig.**.xml文件(本文中使用的是webconfig.rj.xml),编辑内容;
2.修改解决方案包,如下;
3.添加后期部署命令行,如果解决方案里没有这一步,也可以直接在cmd中直接运行;
"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Bin\stsadm.exe" -o copyappbincontent
方法二:使用 SharePoint Foundation 对象模型来修改 Web.config 设置
备注:
2011-01-06:不能在site scope feature使用的原因找到了,是因为 SPWebService.RemoteAdministratorAccessDenied默认为TRUE,将下表中的脚本保存为Set-RemoteAdministratorAccessDenied-False.ps,以管理员身份运行后IISreset,就OK了;
参考:http://unclepaul84.blogspot.com/2010/06/sppersistedobject-xxxxxxxxxxx-could-not.html (过墙)
# AUTHOR: Paul Kotlyar
# CONTACT: unclepaul84@gmail.com
# DESCRIPTION: sets an option on content web service that allows updating of SP Administration objects such as SPJobDefinition from content web applications
function Set-RemoteAdministratorAccessDenied-False()
{
# load sharepoint api libs
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration") > $null
# get content web service
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
# turn off remote administration security
$contentService.RemoteAdministratorAccessDenied = $false
# update the web service
$contentService.Update()
}
Set-RemoteAdministratorAccessDenied-False
缺点是如果上级节点不存在,就没有办法添加SPWebConfigModification实例:比如要在"configuration/connectionStrings"下添加一个"<add name='tongji' connectionString='(请自行修改)Data Source=(loca…….",因为wenconfig默认不存在"configuration/connectionStrings"节点,所以部署时会报错;
2.参考一下URL编写代码