什么是 ASP.NET Web 服务请求生命周期?
在常规 aspx
页面上,我有诸如 Page_Init
、Page_Unload
等事件,这些事件发生 按照明确的顺序。
我有一个提供 [WebMethod()]
的 asmx
页面。是否存在类似事件?特别是,一些允许我初始化一些数据(如 Page_Load
)并进行一些清理(如 Page_Unload
)的事件将非常有用。
(据我所知,asmx代码隐藏类的构造函数似乎在每个WebMethod请求上被调用,即为每个WebMethod请求创建一个新实例,但这只是一个观察而不是我在某处发现的记录......)
On a regular aspx
page, I have events such as Page_Init
, Page_Unload
, etc., which occur in a well-defined order.
I have an asmx
page providing [WebMethod()]
s. Do similar events exist? In particular, some events that allow me to initialize some data (like Page_Load
) and do some clean-up (like Page_Unload
) would be extremely useful.
(As far as I can tell, the constructor of the asmx
code-behind class seems to be called on every WebMethod request, i.e., a new instance is created for every WebMethod request, but this is just an observation and not something I've found documented somewhere...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的 - Otavio 是正确的,ASMX Web 服务没有页面事件,因为它们不是从页面派生的。
但是,该请求遵循常规 ASP.NET 处理管道。
流程中有一个点是执行相关的IHttpHandler。这可以是页面、通用 HTTP 处理程序或 Web 服务。
这是 Web 服务请求执行发生的地方。
所以,这实际上取决于您想在这里做什么。 ctor 应该为预请求执行提供良好的挂钩。如果您正在寻找更早的内容,那么您可能需要挂钩 Global.asax 事件。
Yes - Otavio is correct, there is no Page events for ASMX Web Services, as they do not derive from Page.
However, The request follows the regular ASP.NET processing pipeline.
There is a point in the process where the relevant IHttpHandler is executed. This can be a page, a generic HTTP handler, or a web service.
This is where the web service request execution happens.
So, it really depends on what you're trying to do here. The ctor should provide a good hook-in to pre-request execution. If you're looking for something even earlier, then you will likely need to hook into a Global.asax event.
asmx
对象不是从 Page 派生的,而是从System.Web.Services.WebService
派生的,因此它们不会包含您正在查找的事件。asmx
objects are not derived from Page, rather fromSystem.Web.Services.WebService
, so they will not have the events you are looking for.