首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SharePoint 2010 -尝试使用SPWebConfigModification时出现接收错误

SharePoint 2010 -尝试使用SPWebConfigModification时出现接收错误
EN

Stack Overflow用户
提问于 2010-08-13 23:38:58
回答 3查看 1.4K关注 0票数 0

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

以下是我的功能接收器中的一段代码:

代码语言:javascript
复制
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();
}

下面是在SharePoint ULS查看器中看到的来自错误的堆栈跟踪:

代码语言:javascript
复制
Feature receiver assembly 'MyCompany.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxx', class 'MyCompany.SharePoint.Features.WebConfig.WebConfigFeatureReceiver', method 'FeatureActivated' for feature '3a07b91c-0968-4f14-b2bc-ae0e3f109cf9' threw an exception: System.Xml.XPath.XPathException: '' is an invalid expression.    
at MS.Internal.Xml.XPath.XPathScanner..ctor(String xpathExpr)    
at MS.Internal.Xml.XPath.XPathParser.ParseXPathExpresion(String xpathExpresion)    
at MS.Internal.Xml.XPath.QueryBuilder.Build(String query, Boolean allowVar, Boolean allowKey)    
at System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver)    
at System.Xml.XPath.XPathNavigator.Select(String xpath)    
at System.Xml.XmlNode.SelectSingleNode(String xpath)    
at Microsoft.SharePoint.Administration.SPWebConfigFileChanges.ApplyModificationsWebConfigXmlDocument(XmlDocument xdWebConfig, String filepath)    
at Microsoft.SharePoint.Administration.SPWebApplication.ApplyWebConfigModifications()    
at Microsoft.SharePoint.Administration.SPWebService.ApplyWebConfigModifications()    
at MyCompany.SharePoint.WebConfigModificationFeatureReceiver.FeatureActivated(SPFeatureReceiverProperties properties)    
at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)

在更新期间的某处,XPath表达式中引用了一个空路径。这不在我的特写里。有什么想法吗?

EN

回答 3

Stack Overflow用户

发布于 2010-08-14 02:55:10

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

票数 0
EN

Stack Overflow用户

发布于 2010-08-17 20:14:56

这是我们使用的代码:

代码语言:javascript
复制
                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();

希望能有所帮助

票数 0
EN

Stack Overflow用户

发布于 2017-10-06 19:00:49

在我的例子中,wappCurrent.WebConfigModifications有一些带有无效路径属性的旧值。清除数组已修复此问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3478441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档