I've created a simple HttpModule to log the uses of my existing webservice. There's a dll containing a single class

public class TrackingModule : System.Web.IHttpModule
    public TrackingModule(){}

    public void Init(System.Web.HttpApplication context)
        context.BeginRequest+=new EventHandler(context_BeginRequest);

    public void Dispose()


    private void context_BeginRequest(object sender, EventArgs e)
            Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish( new Exception("Log attept") );
            HttpApplication app = (HttpApplication)sender;
            string method = app.Request.RawUrl;
            SaveUseToDatabase( app.Request.UserHostAddress, method );
        catch( Exception ex )
                Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish( ex );

After compiling the dll I add it to webservice's bin folder and in webservice's web.config I add:

       <add name="TrackingModule" type="WebserviceTrackingModule.TrackingModule, WebserviceTrackingModule"/>

This works fine on my computer, but when I copy it to production server, nothing happens. No new entries in database, no entries logged by ExceptionManager. As if it's not there at all.

What can I be missing?

Edit: After performing another test I can add that it works when I add it for a webservice that has it's own top-level virtual directory. It doesn't work for webservices that reside in virtual directories that are subfolders of another virtual directory.

I know that HttpModules settings are being inherited by subdirectories, but it looks like the existence of parent directory gets in the way.


Does this work?

<add name="TrackingModule" type="WebserviceTrackingModule.TrackingModule" />

And is the context_BeginRequest method definitely being called for each request?

Yes, it works both on my development machine and on production server for other webservice. As I added now in problem description, the problem may come from the parent directory...

OK, I'm answering my own question.

It doesn't work when you define <httpModules> in subdirectory's web.config, even when the subdirectory is configured as an application. The only solution I found so far is to define them within <location> tag in web.config of root application (parent directory).

I don't like it :(


I found the answer to this question in

oh well, a little process-of-elimination never fails me.

After staring at the 3.5-related web.config code, I realized that my module needed to be added to the new section:



instead of least it's working now.

So to translate that:

If you are having a problem with httphandlers

add your handler to the modules node in system.webserver and see if that works Copy the format used for scriptmodule.

Stephen lacy
I'm currently experiencing same issue, but this doesn't seem to "do the trick" for me... Everything works OK on my development machine (Windows 7 + Visual Web Developer 2008 Express), but when I deploy to production server (Windows 2003), it doesn't work.
+2  A: 

I believe I have found a better solution. Attach the module at runtime instead of in the web config. Check out Rick Strahl's blog post for the details.


tnx man =) Had same trouble.