【发布时间】:2013-08-08 18:41:19
【问题描述】:
我目前正在尝试将外部 Web 服务的 URL 添加到我的 SharePoint 2010 场的 Web.config。当我尝试执行此操作时,我收到一条错误消息,指出我缺少 web.config 的连接字符串部分。
查看我正在使用的代码,我的印象是代码未能设置 Web.Config 的连接字符串部分。
当我尝试这样做时,我得到:“无法将 web.config 修改应用于 Web 应用程序 '2962b355-80e1-4183-a958-d4120a94741d'。无法将 web.config 修改应用于文件 'C: \inetpub\wwwroot\wss\VirtualDirectories\80\web.config'。无法将 web.config 修改应用到文件 'C:\inetpub\wwwroot\wss\VirtualDirectories\80\web.config'。指定的节点“配置/connectionStrings" 在 web.config 文件中找不到。无法将 web.config 修改应用于 Web 应用程序 '6fe60f19-9f96-4efb-ba99-a2789354950a'。无法将 web.config 修改应用于文件 'C:\inetpub\ wwwroot\wss\VirtualDirectories\81\web.config'。无法将 web.config 修改应用到文件 'C:\inetpub\wwwroot\wss\VirtualDirectories\81\web.config'。指定的节点“configuration/connectionStrings”在 web.config 文件中找不到。”
我宁愿不必手动修改 web.config 文件以简化 .wsp 文件的安装。
public string Create(string url)
{
var spWebService = SPWebService.ContentService;
// Define the modification(s) to the web.config
var modification1 = new SPWebConfigModification
{
Path = "configuration",
Name = "connectionStrings",
Sequence = 100,
Owner = Owner,
Value = " < connectionStrings > < /connectionStrings > ",
Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode
};
var modification2 = new SPWebConfigModification
{
Path = "configuration/connectionStrings",
Name = string.Format("add[@name='{0}']", KeyName),
Sequence = 100,
Owner = Owner,
Value = url,
Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode
};
// Register the Web.config modification with the web service
spWebService.WebConfigModifications.Add(modification1);
spWebService.WebConfigModifications.Add(modification2);
// Propagate those changes across the farm
spWebService.Update();
spWebService.ApplyWebConfigModifications();
// Set the Url globally
_webServiceUrl = url;
return _webServiceUrl;
}
更新!
将第二个 web.config 修改更改为 Ensure 部分解决了我最初的问题。但是,现在当我尝试运行我得到的代码时:
The '[' character, hexadecimal value 0x5B, cannot be included in a name. Line 1, position 5.
第二次更新
我最终放弃了将配置存储在 Web.Config 中的想法。相反,我选择使用 SPFarm's Property Bag. 在几分钟内启动并运行该实现。感谢您的帮助!
【问题讨论】:
标签: c# asp.net sharepoint sharepoint-2010