开发者

Adding HTTPHandler using SPWebConfigModification

I'm using the following code to add few httpHandlers (for Telerik controls) through the following code.

            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();

But I'm getting the error as

'' is an invalid expression.

That is not very detailed. Any ideas?


Okie, I've fixed it. The error was appearing on ApplyWebConfigModifcations() line. It was holding some previous erroneous web.config change entries. Calling

webApp.WebConfigModifications.Clear()

fixed the issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜