什么是 ASP.NET Web 服务请求生命周期?

发布于 2024-09-28 13:46:14 字数 453 浏览 0 评论 0原文

在常规 aspx 页面上,我有诸如 Page_InitPage_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贱人配狗天长地久 2024-10-05 13:46:14

是的 - 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.

任谁 2024-10-05 13:46:14

asmx 对象不是从 Page 派生的,而是从 System.Web.Services.WebService 派生的,因此它们不会包含您正在查找的事件。

asmx objects are not derived from Page, rather from System.Web.Services.WebService, so they will not have the events you are looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文