0

Is there a way to intercept asp.net ajax webmethods(aspx page static methods)?

i want to intercept before request reaching the method and also after sending the response.

1
  • 1
    What are you trying to do before and after? Commented Jun 29, 2013 at 12:17

1 Answer 1

1

use in global.asax file

    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        //before method colling
        string ss = HttpContext.Current.Request.Url.ToString();//use if it is equal to your page webmethod url  i.e. example.com/default.aspx/GetMessage;
        if(ss == "http://example.com/default.aspx/GetMessage")
        {
            // do your work here
        }
    }

    protected void Application_EndRequest(Object sender, EventArgs e)
    {
        //after method colling
        string ss = HttpContext.Current.Request.Url.ToString();// use if  it is equal to your page webmethod i.e. example.com/default.aspx/GetMessage;

        if(ss=="http://example.com/default.aspx/GetMessage")
        {
            // do your work here
        }
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer, this will help me but if i want to intercept every webmethod is there any way? because this solution i have to write many if else conditions. is there any way i can detect whether it is webmethod or normal page request?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.