C# SharePoint 2010-尝试使用SPWebConfigModification时收到错误

C# SharePoint 2010-尝试使用SPWebConfigModification时收到错误,c#,sharepoint,sharepoint-2010,C#,Sharepoint,Sharepoint 2010,我正在创建SharePoint功能,并在FeatureReceiver中尝试添加SPWebConfigModification。我一直在遵循博客文章中概述的方法 以下是我的功能接收器的一个片段: public override void FeatureActivated(SPFeatureReceiverProperties properties) { var webApp = (SPWebApplication)properties.Feature.Parent; var d

我正在创建SharePoint功能,并在FeatureReceiver中尝试添加SPWebConfigModification。我一直在遵循博客文章中概述的方法

以下是我的功能接收器的一个片段:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    var webApp = (SPWebApplication)properties.Feature.Parent;

    var debugMode = new SPWebConfigModification
                    {
                        Path = "configuration/system.web/customErrors",
                        Name = "mode",
                        Value = "Off",
                        Sequence = 0,
                        Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute,
                        Owner = "MyWebConfigMods"
                    };

    webApp.WebConfigModifications.Add(debugMode); // <------ Error is thrown at this line
    webApp.WebService.ApplyWebConfigModifications();
    webApp.Update();
}

在更新过程中的某个地方,XPath表达式中引用了一个空路径。这不是我的特色。有什么想法吗?

customErrors没有名为debug的属性,您必须引用编译元素

这是我们使用的代码:

                SPWebApplication wappCurrent = (SPWebApplication)properties.Feature.Parent;
                SPWebConfigModification modAuthorizedType = new SPWebConfigModification();
                modAuthorizedType.Name = "authorizedType[@Assembly='Infowise.AssociatedTasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=23853b1f8d5855a5']";
                modAuthorizedType.Owner = "Infowise.Actions";
                modAuthorizedType.Path = "configuration/System.Workflow.ComponentModel.WorkflowCompiler/authorizedTypes";
                modAuthorizedType.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
                modAuthorizedType.Value = @"<authorizedType Assembly=""Infowise.AssociatedTasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=23853b1f8d5855a5"" Namespace=""Infowise.Sharepoint.V3.Fields.Workflow"" TypeName=""*"" Authorized=""True"" />";
                wappCurrent.WebConfigModifications.Add(modAuthorizedType);
                wappCurrent.Update();
                wappCurrent.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();

希望对我有帮助在我的例子中,wappCurrent.WebConfigModifications有一些旧值,其路径属性无效。清除阵列修复了问题。

抱歉,我的示例不正确。我已经更新了它,但是我仍然面临着同样的错误。在我看来,它还可以,您可以从相同的功能对werb.config进行其他更改吗?它似乎找不到正确的元素,但我不明白为什么…不,没有修改似乎有效。我尝试了其他简单的更改,比如在中添加元素。我将在明天发布我们使用的代码。我看不出您的代码有任何问题,但这可能是非常简单的问题,比如XPath名称空间或我遇到过的类似问题。发现很难排除故障。请尝试很好地格式化您的答案,并可能提供一些清除数组的示例代码。
                SPWebApplication wappCurrent = (SPWebApplication)properties.Feature.Parent;
                SPWebConfigModification modAuthorizedType = new SPWebConfigModification();
                modAuthorizedType.Name = "authorizedType[@Assembly='Infowise.AssociatedTasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=23853b1f8d5855a5']";
                modAuthorizedType.Owner = "Infowise.Actions";
                modAuthorizedType.Path = "configuration/System.Workflow.ComponentModel.WorkflowCompiler/authorizedTypes";
                modAuthorizedType.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
                modAuthorizedType.Value = @"<authorizedType Assembly=""Infowise.AssociatedTasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=23853b1f8d5855a5"" Namespace=""Infowise.Sharepoint.V3.Fields.Workflow"" TypeName=""*"" Authorized=""True"" />";
                wappCurrent.WebConfigModifications.Add(modAuthorizedType);
                wappCurrent.Update();
                wappCurrent.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();