HttpHandler 实例和 HttpApplication 对象 - 后者......?

发布于 2024-07-16 02:18:37 字数 999 浏览 2 评论 0原文

一本书展示了一个示例,其中(使用 IIS7 时)配置了以下模块,以便它可以由网站上运行的任何 Web 应用程序(甚至非 asp.net 应用程序)使用。 但是:

  1. 如果为非 asp.net 应用程序调用此模块,那么仍然如何或为什么会创建 HttpApplication 对象,因为非 asp.net 应用程序不在 CLR 上下文中运行(因此 Asp. Net运行时也不会运行)?

  2. 假设 HttpApplication 对象也是为非 asp.net 应用程序创建的,那么为什么 Init() 事件处理程序中的代码必须检查 HttpApplication 是否存在> 物体确实存在吗? 为什么它不存在? 这不是实际实例化 Http 模块实例的 HttpApplication 对象吗?

这是 Http 处理程序:

public class SimpleSqlLogging : IHttpModule
{
  private HttpApplication _CurrentApplication;

  public void Dispose()
  {
      _CurrentApplication = null;
  }

  public void Init(HttpApplication context)
  {
      // Attach to the incoming request event
      _CurrentApplication = context;

      if (context != null)
      {
          context.BeginRequest += new EventHandler(context_BeginRequest);
      }
  }

  void context_BeginRequest(object sender, EventArgs e)
  { ... }
}



A Book showed an example where ( when using IIS7 ) the following module was configured such that it would be used by any web application ( even by non-asp.net apps ) running on a web site. But:

  1. if this module is invoked for non-asp.net application, then how or why would HttpApplication object still be created, since non-asp.net apps don’t run in the context of CLR ( and thus Asp.Net runtime also won’t run )?

  2. Assuming HttpApplication object is also created for non-asp.net apps, why then does the code inside Init() event handler have to check for whether HttpApplication object actually exists? Why wouldn’t it exist? Isn’t this HttpApplication object which actually instantiates Http module instance?

Here is Http handler:

public class SimpleSqlLogging : IHttpModule
{
  private HttpApplication _CurrentApplication;

  public void Dispose()
  {
      _CurrentApplication = null;
  }

  public void Init(HttpApplication context)
  {
      // Attach to the incoming request event
      _CurrentApplication = context;

      if (context != null)
      {
          context.BeginRequest += new EventHandler(context_BeginRequest);
      }
  }

  void context_BeginRequest(object sender, EventArgs e)
  { ... }
}

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

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

发布评论

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

评论(2

夏末 2024-07-23 02:18:37

在 IIS7 中,使用集成管道运行的应用程序池中的应用程序始终是 .NET 应用程序。 该代码只是防御性的。

In IIS7 an application in app pool running with the integrated pipeline is always a .NET application. The code is just being defensive.

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