【问题标题】:How to flush invalid SPWebConfigModifications如何刷新无效的 SPWebConfigModifications
【发布时间】:2012-05-30 18:15:29
【问题描述】:

如何清除无效的 SPWebConfigModifications?

我尝试执行一些无效修改作为解决方案的一部分,但现在我无法摆脱它们,每次我运行 ApplyWebConfigModifications 时它都会尝试执行无效修改。

如何将它们从系统中清除?

【问题讨论】:

    标签: sharepoint-2010 wsp


    【解决方案1】:

    供将来参考(在我的头撞到墙上 3 天后):

    你可以使用这个工具:

    http://ianankers.wordpress.com/2011/07/14/web-config-modification-manager-for-sharepoint-2010/

    它将列出您农场中安装的每个 WebApp 的所有 mod,您可以添加新的和删除旧的。

    该工具只会列出 webapp 级别的修改,如果您在农场级别安装了 mod,则需要运行如下脚本:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Navigation;
    using Microsoft.SharePoint.Administration;
    
    namespace ModTool
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                SPSite site = new SPSite(args[0]);
                SPWebService service = site.WebApplication.Farm.Services.GetValue<SPWebService>();
    
    
                if (args.Length == 1 || string.IsNullOrEmpty(args[1]))
                {
                    Console.Out.WriteLine("Listing all Mods and Owners");
                    foreach (SPWebConfigModification mod in service.WebConfigModifications)
                    {
                        Console.Out.WriteLine("Mod:" + mod.Name + ", Owner:" + mod.Owner);
                    }
                }
                else
                {
                    Console.Out.WriteLine("Removing all mods owner:" + args[1] + ", reference site:" + args[0]);
    
                    List<SPWebConfigModification> toDelete = new List<SPWebConfigModification>();
    
                    foreach (SPWebConfigModification mod in service.WebConfigModifications)
                    {
                        if (mod.Owner == args[1])
                        {
                            toDelete.Add(mod);
                        }
                    }
    
                    Console.Out.WriteLine("Found " + toDelete.Count + "Mods");
    
    
    
                    foreach (SPWebConfigModification mod in toDelete)
                    {
                        service.WebConfigModifications.Remove(mod);
                    }
                    service.Update();
                    SPWebService.ContentService.ApplyWebConfigModifications();
                    Console.Out.WriteLine("Done!!");
                }
            }
        }
    }
    

    用法:

    ModTool http://site - List all the mods for the farm, site is just an entry point
    ModTool http://site owner -Deletes all the mods for the far wich owner is "owner"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-10
      • 2011-01-28
      • 2017-05-19
      • 2018-04-03
      • 2013-06-08
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      相关资源
      最近更新 更多