gpt4 book ai didi

c# - HttpHandler 实例和 HttpApplication 对象 - 后者是否...?

转载 作者:行者123 更新时间:2023-11-30 16:36:34 25 4
gpt4 key购买 nike

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

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

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

这是 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)
{ ... }
}



最佳答案

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

关于c# - HttpHandler 实例和 HttpApplication 对象 - 后者是否...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/702522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com