Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SPWebConfigModification类不会更新中央管理应用程序';s web.config文件_C#_Sharepoint_Sharepoint 2010_Sharepoint Api - Fatal编程技术网

C# SPWebConfigModification类不会更新中央管理应用程序';s web.config文件

C# SPWebConfigModification类不会更新中央管理应用程序';s web.config文件,c#,sharepoint,sharepoint-2010,sharepoint-api,C#,Sharepoint,Sharepoint 2010,Sharepoint Api,使用SharePoint 2010,我尝试使用SPWebConfigModification类对服务器场中的应用程序上的web.config文件进行一些基本更改,包括使用web应用程序范围的功能(功能接收器处理添加/删除修改)的管理中心web.config文件: public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWebApplication webApp =

使用SharePoint 2010,我尝试使用SPWebConfigModification类对服务器场中的应用程序上的web.config文件进行一些基本更改,包括使用web应用程序范围的功能(功能接收器处理添加/删除修改)的管理中心web.config文件:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
        String ownerId = properties.Feature.DefinitionId.ToString();
        List<SPWebConfigModification> modsToAdd = new List<SPWebConfigModification>();

        #region Authentication Providers

        modsToAdd.Add(new SPWebConfigModification()
        {
            Name = "defaultProvider",
            Owner = ownerId,
            Path = "configuration/system.web/membership",
            Sequence = 0,
            Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute,
            Value = "FBA_AD_MP"
        });

        modsToAdd.Add(new SPWebConfigModification()
        {
            Name = "add [@name=\"FBA_AD_MP\"] [@type=\"System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"] [@connectionStringName=\"ADFBAConnectionString\"] [@enableSearchMethods=\"true\"] [@attributeMapUsername=\"userPrincipalName\"]",
            Owner = ownerId,
            Path = "configuration/system.web/membership/providers",
            Sequence = 0,
            Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
            Value = "<add name=\"FBA_AD_MP\" type=\"System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\" connectionStringName=\"ADFBAConnectionString\" enableSearchMethods=\"true\" attributeMapUsername=\"userPrincipalName\" />"
        });

        #endregion

        #region Connection Strings

        modsToAdd.Add(new SPWebConfigModification()
        {
            Name = "connectionStrings",
            Owner = ownerId,
            Path = "configuration",
            Sequence = 0,
            Type = SPWebConfigModification.SPWebConfigModificationType.EnsureSection,
            Value = "<connectionStrings />"
        });

        modsToAdd.Add(WebConfigModificationsUtility.CreateConnectionStringModification(ownerId, 1, "ADFBAConnectionString", properties.Feature.Properties["ADFBAConnectionString"].Value));

        #endregion

        WebConfigModificationsUtility.AddWebConfigModifications(webApp, modsToAdd.ToArray());
    }
在内容应用程序上一切正常,但当尝试激活central admin web应用程序上的功能时,SPWebConfigModificaiton项永远不会写入web.config文件。我已经验证了代码执行时没有异常。此外,我的功能接收器尝试删除停用时所做的任何修改:

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
            String ownerId = properties.Feature.DefinitionId.ToString();
            WebConfigModificationsUtility.RemoveWebConfigModifications(webApp, ownerId);
        }
public static void RemoveWebConfigModifications(SPWebApplication webApp, String ownerId, Boolean persistChanges)
        {            
            RemoveWebConfigModifications(webApp, persistChanges, webApp.WebConfigModifications.Where(x => x.Owner == ownerId).ToArray());
        }
public static void RemoveWebConfigModifications(SPWebApplication webApp, Boolean persistChanges, params SPWebConfigModification[] modificationsToRemove)
        {
            foreach (SPWebConfigModification curMod in modificationsToRemove)
            {
                SPWebService.ContentService.WebApplications[webApp.Id].WebConfigModifications.Remove(curMod);                
            }

            if (persistChanges)
            {
                PersistWebConfigModifications(webApp);
            }
        }
当此代码在Central Admin web应用程序上运行时,它会找到在功能激活中创建的四个修改并成功删除它们,但这两个操作实际上都没有更改web应用程序的web.config文件;它甚至不被触摸,最后编辑日期的时间戳始终保持不变


我发现很多博客都在谈论SPWebConfigModification类的继承技巧,大多数问题都存在于正确使用Name和Owner属性,以及使用SPWebService静态属性正确持久化更改,但我可以说我遵循了所有推荐的做法。我开始怀疑API中有一个bug,但我想知道是否有人在SharePoint 2010中成功地做到了这一点,或者我是否应该打开Reflector,看看有什么效果?

SPWebConfigMondition不会更新中央管理局网站

与ContentService一样,SPWebService有一个AdministrationService对象,该对象也有一个WebApplications集合。使用管理服务访问您的CentralAdmin web应用程序。

是否有任何文档记录了该类与管理中心网站不兼容的引用?API文档中没有什么特别之处,这篇文章中至少有一些间接证据:在MSDN论坛上,它在SharePoint 2007中工作。
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
            String ownerId = properties.Feature.DefinitionId.ToString();
            WebConfigModificationsUtility.RemoveWebConfigModifications(webApp, ownerId);
        }
public static void RemoveWebConfigModifications(SPWebApplication webApp, String ownerId, Boolean persistChanges)
        {            
            RemoveWebConfigModifications(webApp, persistChanges, webApp.WebConfigModifications.Where(x => x.Owner == ownerId).ToArray());
        }
public static void RemoveWebConfigModifications(SPWebApplication webApp, Boolean persistChanges, params SPWebConfigModification[] modificationsToRemove)
        {
            foreach (SPWebConfigModification curMod in modificationsToRemove)
            {
                SPWebService.ContentService.WebApplications[webApp.Id].WebConfigModifications.Remove(curMod);                
            }

            if (persistChanges)
            {
                PersistWebConfigModifications(webApp);
            }
        }