一本书展示了一个示例,其中(当使用IIS7时)配置了以下模块,使其能够被运行在网站上的任何web应用程序(甚至是非ASP.NET应用程序)使用。但是:
如果该模块是为非Asp.Net应用程序调用的,那么如何或为什么仍然会创建对象,因为非ASP.NET应用程序不会在CLR上下文中运行(因此Asp.Net运行时也不会运行)?。
假设
HttpApplication对象,那么为什么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)
{ ... }
}发布于 2009-03-31 19:06:02
在IIS7中,与集成管道一起运行的应用程序池中的应用程序始终是.NET应用程序。代码只是防御性。
发布于 2010-03-23 04:37:21
关于HttpHander:http://msdn.microsoft.com/en-us/magazine/cc188942.aspx的链接
https://stackoverflow.com/questions/702522
复制相似问题