Global.asax 中的自动事件连接
我想知道是否有一种方法可以自动存根 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
ASP.Net 运行时使用反射来动态查找名称为“Application_Start”、“Session_Start”等的方法,然后将它们绑定到 HttpApplication 类上的相应事件。 您只需在 Global.asax.cs 中包含一个方法,其名称为“Application_”,后跟事件名称,即可有效地绑定到任何 HttpApplication 事件。 例如,要利用 EndRequest 事件,请将其添加到 Global.asax.cs 文件中:
请参阅此 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:
See this Blog Entry from Rick Strahl for a bunch of helpful information on how this is done.
HttpApplication
的所有事件 类可以在 global.asax 中拥有一个处理程序。All of the events of the
HttpApplication
class can have a handler in the global.asax.在创建所有模块对象并调用其每个 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.
我不太明白“自动存根”事件处理程序是什么意思? 就像输入“覆盖”并让智能感知告诉哪些事件处理程序可用? 恐怕不存在...
不过,这里有一个显示可用内容的链接:
不过,似乎在任何地方都找不到任何明确的、完整的列表:-(
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