Search code examples
asp.netiis-7httpmodulewebmethod

IHttpModule is not being called for my WebMethod


Ok, so I have an existing application to which I have added a custom HttpModule. I'm registering two events in the Init() method (PreRequestHandlerExecute and PostRequestHandlerExecute). The HttpModule gets called for every 'normal' request. But not I have created an .aspx containing a few WebMethods that are being called for ajaxifying some UI components. The WebMethod gets called nicely, but the trouble is that my HttpModule does NOT get called at all (no events, no init, even no constructor) when accessing the WebMethod. The module gets called nicely when accessing the .aspx in question as a 'normal' request. But it refuses to be called when calling the WebMethod.

My .aspx looks like this:

public partial class SelectionListService : System.Web.UI.Page
{
    [WebMethod]
    [ScriptMethod]
    public static RadComboBoxData GetItemsAsRadComboBoxData(RadComboBoxContext context)
    {
       ...
    }
}

My HttpModule look like this:

public class MyModule : IHttpModule, IRequiresSessionState
{
    public MyModule ()
    {
    }

    public void Init(HttpApplication context)
    {
        context.PreRequestHandlerExecute += new EventHandler(Application_PreRequestHandlerExecute);
        context.PostRequestHandlerExecute += new EventHandler(Application_PostRequestHandlerExecute);
    }

    private void Application_PreRequestHandlerExecute(object sender, EventArgs e)
    {
       ...
    }

    private void Application_PostRequestHandlerExecute(object sender, EventArgs e)
    {
       ...
    }
 }

I have been digging into this for quite some time now, but I just can't get it to work. Any ideas?

PS1: the BeginRequest, etc in global.asax.cs do get called when accessing the WebMethod. PS2: I'm running IIS7 on Windows7.


Solution

  • since PageMethods must be static, an instance of the Page class with all it's events and the ASP.NET pipeline never happens. You simply get the result of your PageMethod call, and that is all.