HttpHandler 实例和 HttpApplication 对象 - 后者......?
一本书展示了一个示例,其中(使用 IIS7 时)配置了以下模块,以便它可以由网站上运行的任何 Web 应用程序(甚至非 asp.net 应用程序)使用。 但是:
如果为非 asp.net 应用程序调用此模块,那么仍然如何或为什么会创建 HttpApplication 对象,因为非 asp.net 应用程序不在 CLR 上下文中运行(因此 Asp. Net运行时也不会运行)?
假设
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:
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 )?
Assuming
HttpApplication
object is also created for non-asp.net apps, why then does the code inside Init() event handler have to check for whetherHttpApplication
object actually exists? Why wouldn’t it exist? Isn’t thisHttpApplication
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 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.
关于 HttpHander 的链接: http://msdn.microsoft.com/en-us /杂志/cc188942.aspx
A link about HttpHander : http://msdn.microsoft.com/en-us/magazine/cc188942.aspx