ASMX equivalent of Page_Init?

前端 未结 3 2186
醉酒成梦
醉酒成梦 2021-02-20 16:24

I have some code I would like to execute very early in the lifecycle of a call to an ASMX function. For our ASPX pages, this code is in the Page_Init() function on a base class

3条回答
  •  耶瑟儿~
    2021-02-20 16:42

    Very good question!

    Not entirely sure, but i believe that execution of ASMX Web Services is slightly different to ASPX Pages - there is no "Page Lifecycle" (i.e there is no initialization of controls in order to render HTML - as the response is generally XML).

    Your only options would be to hook into one of the Application events in Global.asax - the only suitable event would be Application_PreRequestHandlerExecute.

    You can try Application_BeginRequest, but i believe this is only for ASP.NET Page Requests, not Web Service calls.

    You're other option (as you said) is to create a base class for your web services, then call the common base method in all of your web methods at the very first line. You would have to repeat this call in ALL of your web methods. Or if you have all your web methods in a single web service file (ASMX), then just create a regular static method (dont decorate it with the WebMethod attribute) and call that.

提交回复
热议问题