1

我知道我们可以在 asp.net Web 项目中处理不同版本的 web.config 文件(例如调试、暂存和发布)。我们如何利用这个 asp.net 功能在 SharePoint 项目中做同样的事情(请记住,场中可能有不止一台服务器,即每台服务器都需要使用配置设置进行更新)?

4

1 回答 1

0

You should register your web.config changes using the SPWebConfigModification class during the FeatureActivated event of a FeatureReceiver. Here is an article on how to use them. Then you could have 3 xml files with your different configurations for Development/Stage/Production. During your FeatureActivated event you could load the configuration for a particular environment based on the address of the current site. For example, you would have a stage website called 'mysite.stage.com' and so the xml would be '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...
}
于 2012-04-26T15:44:18.613 回答