Getting “Expression must evaluate to a node-set” exception while adding HttpHandler entries to web.config programmatically?

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/31308

I'm trying to update web.config in SharePoint when the feature is activated to register an HttpHandler. The code inside receiver is

var configModifications = new SPWebConfigModification
{
    Owner = "Request Handler",
    Path = "configuration/system.webServer/handlers",
    Name = "add[@name='RequestHandler']",
    Sequence = 0,
    Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
    Value = "<add name=\"RequestHandler\" verb=\"*\" path=\"*.html\" type=\"DivisionRequestHandler.RequestHandler\" resourceType=\"File\" preCondition=\"integratedMode\" />"
};

webApplication.WebConfigModifications.Add(configModifications);
webApplication.Update();
webApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();

When I'm deploying feature I have received the following error: "Expression must evaluate to a node-set." Handler assembly is deployed to application bin folder via SharePoint solution without any issues. Also, I tried to add handler via IIS Handler Mapping. This working successfully without any issues. But I'm in a need to add to web.config programmatically via SharePoint feature.

Has any of you experienced the same thing? Any suggestion?

有帮助吗?

解决方案

The easiest way to create a HttpHandler is to create a .ashx file. After you create an .ashx file that defines an HttpHandler component, you must deploy it within the \LAYOUTS directory as you would deploy a custom application page. See this post for more datails.

In this case you should not modify web.cfg. In my practice it is the best way.

许可以下: CC-BY-SA归因
scroll top