如何处理sharepoint中Web配置文件的调试版本和发布版本?
问题描述:
我知道我们可以在asp.net web项目中处理不同版本的web.config文件(如debug,staging和release)。我们如何通过利用这个asp.net功能在SharePoint项目中做到这一点(要记住,服务器场中可能有多个服务器,即每个服务器需要使用配置设置进行更新)?如何处理sharepoint中Web配置文件的调试版本和发布版本?
答
您应该在FeatureReceiver
的FeatureActivated
事件中使用SPWebConfigModification
类注册您的web.config更改。以下是关于如何使用它们的article。然后,您可以在开发/舞台/制作中使用3种不同配置的xml文件。在您的FeatureActivated
事件中,您可以根据当前网站的地址加载特定环境的配置。例如,你将有一个名为'mysite.stage.com'的舞台网站,因此xml将是'mysite.stage.com.xml'。
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
base.FeatureActivated(properties);
SPSite siteCollection = properties.Feature.Parent as SPSite;
string host =
siteCollection.WebApplication.GetResponseUri(SPUrlZone.Default).Host;
string fileName = String.Format("{0}.xml", host);
// Read the xml and make web config modifications...
}