开发者

IHttpModule is not being called for my WebMethod

开发者 https://www.devze.com 2023-04-02 16:25 出处:网络
Ok, so I have an existing application to which I have added a custom HttpModule. I\'m regist开发者_运维百科ering two events in the Init() method (PreRequestHandlerExecute and PostRequestHandlerExecute

Ok, so I have an existing application to which I have added a custom HttpModule. I'm regist开发者_运维百科ering 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.


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.


I have a project that had the same problem. We found that the first event in the pipeline that we could get to fire for the WebMethods was the AcquireRequestState event. We hooked into that with our HttpModule in order to do the authorization checking required for the application.

I don't know what your pre and post request handlers do, but maybe you could shift some of the logic into the AcquireRequestState event handler.

0

精彩评论

暂无评论...
验证码 换一张
取 消