.NET and SharePoint HttpModules

Today I ran into a problem where my HttpModule was not working. No matter what I did I could not access my code under Visual Studio debugger. In other words my breakpoints did not work.

After a long time of wondering and some Googling I found out that the problem was related to how my HttpModule was being registered to the web application.

In my case I was working on a SharePoint 2010 project and was adding the module registration through a feature.

To put it simple if you are using IIS7 you need to register it under the “modules” element in the web.config file. If you are using lets say IIS6 then you need to register the module under the httpmodules element of  the web.config file.

Example under IIS7:

return new SPWebConfigModification(“add[@name=’My.HttpModule’]”, “configuration/system.web/modules”)
{
Value = @”<add name=””My.HttpModule”” type=””myassembly namespace info etc”” />”,
Owner = properties.Feature.DefinitionId.ToString(),
Sequence = 0,
Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode
};

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s