internal class MapHandlerExecutionStep : HttpApplication.IExecutionStep 
{ 
// Fields 
private HttpApplication _application; 
// Methods 
internal MapHandlerExecutionStep(HttpApplication app) 
{ 
this._application = app; 
} 
void HttpApplication.IExecutionStep.Execute() 
{ 
HttpContext context = this._application.Context; 
HttpRequest request = context.Request; 
if (EtwTrace.IsTraceEnabled(5, 1)) 
{ 
EtwTrace.Trace(EtwTraceType.ETW_TYPE_MAPHANDLER_ENTER, context.WorkerRequest); 
} 
context.Handler = this._application.MapHttpHandler(context, request.RequestType, request.FilePathObject, request.PhysicalPathInternal, false); 
if (EtwTrace.IsTraceEnabled(5, 1)) 
{ 
EtwTrace.Trace(EtwTraceType.ETW_TYPE_MAPHANDLER_LEAVE, context.WorkerRequest); 
} 
} 
// Properties 
bool HttpApplication.IExecutionStep.CompletedSynchronously 
{ 
get 
{ 
return true; 
} 
} 
bool HttpApplication.IExecutionStep.IsCancellable 
{ 
get 
{ 
return false; 
} 
} 
}
里面的调用主要是
context.Handler = this._application.MapHttpHandler(context, request.RequestType, request.FilePathObject, request.PhysicalPathInternal, false);
而HttpApplication的MapHttpHandler如下:
复制代码 代码如下:
internal IHttpHandler MapHttpHandler(HttpContext context, string requestType, VirtualPath path, string pathTranslated, bool useAppConfig) 
{ 
IHttpHandler handler = (context.ServerExecuteDepth == 0) ? context.RemapHandlerInstance : null; 
using (new ApplicationImpersonationContext()) 
{ 
if (handler != null) 
{ 
return handler; 
} 
HttpHandlerAction mapping = this.GetHandlerMapping(context, requestType, path, useAppConfig); 
if (mapping == null) 
{ 
PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_NOT_FOUND); 
PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_FAILED); 
throw new HttpException(SR.GetString("Http_handler_not_found_for_request_type", new object[] { requestType })); 
} 
IHttpHandlerFactory factory = this.GetFactory(mapping); 
try 
{ 
IHttpHandlerFactory2 factory2 = factory as IHttpHandlerFactory2; 
if (factory2 != null) 
{ 
handler = factory2.GetHandler(context, requestType, path, pathTranslated); 
} 
else 
{ 
handler = factory.GetHandler(context, requestType, path.VirtualPathString, pathTranslated); 
} 
} 
catch (FileNotFoundException exception) 
{ 
if (HttpRuntime.HasPathDiscoveryPermission(pathTranslated)) 
{ 
throw new HttpException(0x194, null, exception); 
} 
throw new HttpException(0x194, null); 
} 
catch (DirectoryNotFoundException exception2) 
{ 
if (HttpRuntime.HasPathDiscoveryPermission(pathTranslated)) 
{ 
throw new HttpException(0x194, null, exception2); 
} 
throw new HttpException(0x194, null); 
} 
catch (PathTooLongException exception3) 
{ 
if (HttpRuntime.HasPathDiscoveryPermission(pathTranslated)) 
{ 
throw new HttpException(0x19e, null, exception3); 
} 
throw new HttpException(0x19e, null); 
} 
if (this._handlerRecycleList == null) 
{ 
this._handlerRecycleList = new ArrayList(); 
} 
this._handlerRecycleList.Add(new HandlerWithFactory(handler, factory)); 
} 
return handler; 
}
在MapHttpHandler里创建了IHttpHandlerFactory,进而创建了httphandler。
在ApplicationStepManager中BuildSteps的方法有steps.Add(new HttpApplication.CallHandlerExecutionStep(app));这么一句,这就是注册调用我们hanndler的地方。
复制代码 代码如下:
