在上一篇关于管线的随笔中已经提及了管线,通过对管线的分析,我们可以得到下面几个结论:路由系统由URLRoutingModule模块实现,它订阅了PostResolvRequestCache事件;路由系统通过查阅路由并尽可能的通过RemapHandler方法,确定excuteHandler阶段执行的IHttphandler。这一篇随笔想详细谢谢路由的定义、注册和导航的具体过程。
路由系统的导航过程定义于URLRoutingModule,具体实现如下:
1 public virtual void PostResolveRequestCache(HttpContextBase context) 2 { 3 RouteData routeData = this.RouteCollection.GetRouteData(context); 4 if (routeData != null) 5 { 6 IRouteHandler routeHandler = routeData.RouteHandler; 7 if (routeHandler == null) 8 { 9 throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.GetString("UrlRoutingModule_NoRouteHandler"), new object[0])); 10 } 11 if (!(routeHandler is StopRoutingHandler)) 12 { 13 RequestContext requestContext = new RequestContext(context, routeData); 14 context.Request.RequestContext = requestContext; 15 IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext); 16 if (httpHandler == null) 17 { 18 throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, SR.GetString("UrlRoutingModule_NoHttpHandler"), new object[] { routeHandler.GetType() })); 19 } 20 if (httpHandler is UrlAuthFailureHandler) 21 { 22 if (!FormsAuthenticationModule.FormsAuthRequired) 23 { 24 throw new HttpException(0x191, SR.GetString("Assess_Denied_Description3")); 25 } 26 UrlAuthorizationModule.ReportUrlAuthorizationFailure(HttpContext.Current, this); 27 } 28 else 29 { 30 context.RemapHandler(httpHandler); 31 } 32 } 33 } 34 } 35 36 37 38