locked
PreRequestHandlerExecute doesn't fire on PageMethod calls RRS feed

  • Question

  • User-1982983517 posted

    I created a HttpModule. Inside the module I am subscribing to the request processing events like so (My HttpModule's purpose is to measure the request begin and end times of my request to the web pages):

                    public void Init(HttpApplication application)
                    {
                        if (PerformanceLoggingHelper.LoggingEnabled)
                        {
                            // Register event handlers.
                            application.BeginRequest += new EventHandler(OnBeginRequest);
                            application.PostMapRequestHandler += new EventHandler(OnPostMapRequestHandler);
                            application.PreRequestHandlerExecute += new EventHandler(OnPreRequestHandlerExecute);
                            application.EndRequest += new EventHandler(OnEndRequest);
                        }
                    }
    I have a PageMethod defined in one of my web pages. From the client side when the javascript function calls the page method, 
    only the PostMapRequestHandler and EndRequest  events are fired. 
    Can any one help me in knowing the reason?
     Thanks.

     

    Monday, May 18, 2009 2:27 PM

Answers

  • User2116698404 posted

     I have run into this same issue.  When using a PageMethod in my ASP.Net page to call back to a static method with the [WebMethod] decorator, I am not seeing the PreRequestHandlerExecut.  After doing a lot of research I think that the reason is explained with this quote from this post.

    "If the request is for a class that implements System.Web.UI.Page and it is a rest method call, the WebServiceData class (that was explained in a previous post) is used to call the requested method from the Page. After the method has been called, the CompleteRequest method is called, bypassing all pipeline events and executing the EndRequest method. This allows MS AJAX to be able to call a method on a page instead of having to create a web service to call a method."

    If you look at the page method request with Fiddler, you will see that it looks something like this.  http://<your server>/page.aspx/<webmethod name>/  and the content type is "application/json".  My bet is this is being treated like a rest method call vs a standard page or web service call.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 26, 2009 12:41 PM

All replies

  • User-1136466523 posted

    Hi,

    From your description, you mentioned that you are calling the page method from the javascript, I'm not quite sure what you mean by that, are you just calling the page from javascript side?

    HttpApplication.PreRequestHandlerExecute Event occurs just before ASP.NET starts executing an event handler while HttpApplication.BeginRequest Event occurs as the first event in the HTTP pipeline chain of execution when ASP.NET responds to a request. Please double check on your code, add breakpoints in your code and try to see if it's too late to fire those events.

    Thanks.

    Wednesday, May 20, 2009 10:58 PM
  • User-1982983517 posted

    What I meant by calling the page method from javascript is -- In the code behind, I am adding "mouseover" attribute to a Label control. The mouseover attribute's value is a call to a client JavaScript function. Within this function, I am calling my PageMethod defined in the code behind file. The pagemethod returns me some values which I display in a html table using XSLT and DHTML.

    Basically I'm creating a client function for the mouseover tooltip of the Label control. When you hover on the Label text on the browser page, the pagemethod is executed and a html table is shown as a tooltip.

    Now, what is happening is that when the pagemethod call is initiated from the client, on the server side the HttpApplication.BeginRequest and HttpApplication.PreRequestHandlerExecute events are not fired. And I have tested with breakpoints.

    However, I noticed that the Application.PostMapRequestHandler and Application.EndRequest events do get fired.

    Hope this helps.

    Thursday, May 21, 2009 11:05 AM
  • User2116698404 posted

     I have run into this same issue.  When using a PageMethod in my ASP.Net page to call back to a static method with the [WebMethod] decorator, I am not seeing the PreRequestHandlerExecut.  After doing a lot of research I think that the reason is explained with this quote from this post.

    "If the request is for a class that implements System.Web.UI.Page and it is a rest method call, the WebServiceData class (that was explained in a previous post) is used to call the requested method from the Page. After the method has been called, the CompleteRequest method is called, bypassing all pipeline events and executing the EndRequest method. This allows MS AJAX to be able to call a method on a page instead of having to create a web service to call a method."

    If you look at the page method request with Fiddler, you will see that it looks something like this.  http://<your server>/page.aspx/<webmethod name>/  and the content type is "application/json".  My bet is this is being treated like a rest method call vs a standard page or web service call.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 26, 2009 12:41 PM
  • User-1982983517 posted

    That helps. Hope what you said is correct. Thanks.

    Tuesday, May 26, 2009 2:24 PM
  • User2116698404 posted

    It seems to work out like it is correct.  I have played around with this and run tests with most of the HTTP module events hooked up and what I am seeing agrees with the statement I quoted.  Maybe an MS person can come back and verify this for us!

    Tuesday, May 26, 2009 2:44 PM