Global.asax 中的自动事件连接

发布于 2024-07-15 03:59:49 字数 145 浏览 10 评论 0原文

我想知道是否有一种方法可以自动存根 Global.asax 的事件处理程序? 到目前为止,我还没有找到任何如何执行此操作的示例。 看来我必须找到我可用的代表姓名列表并手动输入它们。

Intellisense 似乎也没有提供有关该主题的任何有用信息。

I'm wondering if there's a way to automatically stub in the Global.asax's event handlers? Thus far, I've not been able to find any examples of how to do this. Seems I have to just find the list of delegate names available to me and type them in manually.

Intellisense doesn't seem to lend any useful info on the subject either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

隱形的亼 2024-07-22 03:59:49

ASP.Net 运行时使用反射来动态查找名称为“Application_Start”、“Session_Start”等的方法,然后将它们绑定到 HttpApplication 类上的相应事件。 您只需在 Global.asax.cs 中包含一个方法,其名称为“Application_”,后跟事件名称,即可有效地绑定到任何 HttpApplication 事件。 例如,要利用 EndRequest 事件,请将其添加到 Global.asax.cs 文件中:

    protected void Application_EndRequest(object sender, EventArgs e)
    {
        // Your code here
    }

请参阅此 Rick Strahl 的博客条目,提供了有关如何完成此操作的大量有用信息。

The ASP.Net runtime uses reflection to dynamically look for methods with names like "Application_Start", "Session_Start" etc. and then binds them to the corresponding events on the HttpApplication class. You can effectively bind to any of the HttpApplication events simply by including a method in Global.asax.cs whose name is "Application_" followed by the name of the event. For example, to utilize the EndRequest event, add this to your Global.asax.cs file:

    protected void Application_EndRequest(object sender, EventArgs e)
    {
        // Your code here
    }

See this Blog Entry from Rick Strahl for a bunch of helpful information on how this is done.

寂寞笑我太脆弱 2024-07-22 03:59:49

HttpApplication 的所有事件 类可以在 global.asax 中拥有一个处理程序。

All of the events of the HttpApplication class can have a handler in the global.asax.

沒落の蓅哖 2024-07-22 03:59:49

在创建所有模块对象并调用其每个 Init 方法之后,将调用 HttpApplication.Init 方法,这提供了设置事件处理程序、初始化 HttpModule 实例变量以及将事件处理程序连接到托管 HttpApplication。

asax 类中的方法名称是用于在 Web.config 文件中注册模块的 name 属性值、下划线和
事件的名称。

HttpApplication.Init method is called after all of the module objects have been created and each of their Init methods has been called, which presents the perfect opportunity to set up event handlers, initialize a HttpModule?s instance variables, and to wireup event handlers to the hosting HttpApplication.

method name in asax Class is the concatenation of the value of the name attribute used to register the module in the Web.config file, an underscore, and
the name of the event.

感情废物 2024-07-22 03:59:49

我不太明白“自动存根”事件处理程序是什么意思? 就像输入“覆盖”并让智能感知告诉哪些事件处理程序可用? 恐怕不存在...

不过,这里有一个显示可用内容的链接:

不过,似乎在任何地方都找不到任何明确的、完整的列表:-(

Marc

I don't quite understand what you mean by "automatically stub" the event handlers? Like typing the "override" and getting Intellisense telling what event handlers are available? Afraid that's not there...

Here is a link showing what's avaialble, though:

Can't seem to find any definitive, complete listing anywhere, though :-(

Marc

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