Sharepoint 使用SPWebConfigModification添加HTTPHandler

Sharepoint 使用SPWebConfigModification添加HTTPHandler,sharepoint,sharepoint-2007,sharepoint-2010,wss,Sharepoint,Sharepoint 2007,Sharepoint 2010,Wss,我正在使用下面的代码通过下面的代码添加几个HttpHandler(用于Telerik控件) SPWebConfigModification webConfig = null; webConfig = new SPWebConfigModification(); webConfig.Owner = featureID; webConfig.Type = SPWebConfigModification.

我正在使用下面的代码通过下面的代码添加几个HttpHandler(用于Telerik控件)

            SPWebConfigModification webConfig = null;

            webConfig = new SPWebConfigModification();
            webConfig.Owner = featureID;
            webConfig.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
            webConfig.Path = "/configuration/system.web/httpHandlers";
            webConfig.Name = "add[@path='Telerik.ReportViewer.axd']";
            webConfig.Value = "<add verb=\"*\" path=\"Telerik.ReportViewer.axd\" type = \"Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=4.2.10.1110, Culture=neutral, PublicKeyToken=a9d7983dfcc261be\" />";
            webApp.WebConfigModifications.Add(webConfig);

            webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
            webApp.Update();

            webConfig = new SPWebConfigModification();
            webConfig.Owner = featureID;
            webConfig.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
            webConfig.Path = "/configuration/system.web/httpHandlers";
            webConfig.Name = "add[@path='ChartImage.axd']";
            webConfig.Value = "<add path=\"ChartImage.axd\" verb=\"*\" type=\"Telerik.Web.UI.ChartHttpHandler, Telerik.Web.UI, Version=2010.2.826.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4\" validate=\"false\" />";
            webApp.WebConfigModifications.Add(webConfig);

            webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
            webApp.Update();

            webConfig = new SPWebConfigModification();
            webConfig.Owner = featureID;
            webConfig.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
            webConfig.Path = "/configuration/system.web/httpHandlers";
            webConfig.Name = "add[@path='Telerik.Web.UI.WebResource.axd']";
            webConfig.Value = "<add path=\"Telerik.Web.UI.WebResource.axd\" verb=\"*\" type=\"Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2010.2.826.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4\" validate=\"false\"/>";
            webApp.WebConfigModifications.Add(webConfig);

            webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
            webApp.Update();

            webConfig = new SPWebConfigModification();
            webConfig.Owner = featureID;
            webConfig.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
            webConfig.Path = "/configuration/system.web/httpHandlers";
            webConfig.Name = "remove[@path='Telerik.ReportViewer.axd']";
            webConfig.Value = "<add verb=\"*\" path=\"Telerik.ReportViewer.axd\" type = \"Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=4.2.10.1110, Culture=neutral, PublicKeyToken=a9d7983dfcc261be\" />";
            webApp.WebConfigModifications.Add(webConfig);

            webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
            webApp.Update();

            webConfig = new SPWebConfigModification();
            webConfig.Owner = featureID;
            webConfig.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
            webConfig.Path = "/configuration/system.web/httpHandlers";
            webConfig.Name = "remove[@path='Telerik.ReportViewer.axd_*']";
            webConfig.Value = "<add name=\"Telerik.ReportViewer.axd_*\" path=\"Telerik.ReportViewer.axd\" verb=\"*\" type=\"Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=4.2.10.1110, Culture=neutral, PublicKeyToken=a9d7983dfcc261be\" preCondition=\"integratedMode,runtimeVersionv2.0\" />";
            webApp.WebConfigModifications.Add(webConfig);

            webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
            webApp.Update();
spwebconfig修改webConfig=null;
webConfig=新的SPWebConfigModification();
webConfig.Owner=featureID;
webConfig.Type=SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
webConfig.Path=“/configuration/system.web/httpHandlers”;
webConfig.Name=“添加[@path='Telerik.ReportViewer.axd']”;
webConfig.Value=“”;
webApp.WebConfigModifications.Add(webConfig);
webApp.Farm.Services.GetValue().ApplyWebConfigModifications();
webApp.Update();
webConfig=新的SPWebConfigModification();
webConfig.Owner=featureID;
webConfig.Type=SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
webConfig.Path=“/configuration/system.web/httpHandlers”;
webConfig.Name=“添加[@path='ChartImage.axd']”;
webConfig.Value=“”;
webApp.WebConfigModifications.Add(webConfig);
webApp.Farm.Services.GetValue().ApplyWebConfigModifications();
webApp.Update();
webConfig=新的SPWebConfigModification();
webConfig.Owner=featureID;
webConfig.Type=SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
webConfig.Path=“/configuration/system.web/httpHandlers”;
webConfig.Name=“添加[@path='Telerik.Web.UI.WebResource.axd']”;
webConfig.Value=“”;
webApp.WebConfigModifications.Add(webConfig);
webApp.Farm.Services.GetValue().ApplyWebConfigModifications();
webApp.Update();
webConfig=新的SPWebConfigModification();
webConfig.Owner=featureID;
webConfig.Type=SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
webConfig.Path=“/configuration/system.web/httpHandlers”;
webConfig.Name=“remove[@path='Telerik.ReportViewer.axd']”;
webConfig.Value=“”;
webApp.WebConfigModifications.Add(webConfig);
webApp.Farm.Services.GetValue().ApplyWebConfigModifications();
webApp.Update();
webConfig=新的SPWebConfigModification();
webConfig.Owner=featureID;
webConfig.Type=SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
webConfig.Path=“/configuration/system.web/httpHandlers”;
webConfig.Name=“remove[@path='Telerik.ReportViewer.axd_*'”;
webConfig.Value=“”;
webApp.WebConfigModifications.Add(webConfig);
webApp.Farm.Services.GetValue().ApplyWebConfigModifications();
webApp.Update();
但我得到的错误是

“”是无效的表达式


这不是很详细。有什么想法吗?

好的,我已经修好了。错误出现在
applyWebConfigModifications()
行。它保存了一些以前错误的web.config更改条目。召唤

webApp.WebConfigModifications.Clear()

修复了该问题。

在哪一行发生异常?想法-是的,检查异常的行号。或者,将visual studio连接到W3WP进程,然后再次尝试激活您的功能。错误出现在我使用ApplyWebConfigModifications()应用web配置更改的行中。