コード例 #1
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;

            SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);

            WebSiteControllerWebConfigManager.ClearWebConfigModifications(webApp);
            SPWebConfigModification mod = WebSiteControllerWebConfigManager.GetHttpModuleEntry();

            if (!webApp.WebConfigModifications.Contains(mod))
            {
                webApp.WebConfigModifications.Add(mod);
            }

            mod = WebSiteControllerWebConfigManager.GetModuleEntry();
            if (!webApp.WebConfigModifications.Contains(mod))
            {
                webApp.WebConfigModifications.Add(mod);
            }

            try
            {
                webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                webApp.Update();
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                //ex.ToString();
            }
        }
コード例 #2
0
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;

            SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
            webApp.WebConfigModifications.Remove(WebSiteControllerWebConfigManager.GetHttpModuleEntry());
            webApp.WebConfigModifications.Remove(WebSiteControllerWebConfigManager.GetModuleEntry());
            webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
            webApp.Update();
        }