Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.