.NET FrameWork4在系统全局配置文件(如在如下目录中C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config)

中添加了一个名字叫UrlRoutingModule的HttpModule

【深入ASP.NET原理系列】--Asp.Net Mvc和Asp.Net WebForm实际上共用一套ASP.NET请求管道

通过反编译工具我们可以看见

【深入ASP.NET原理系列】--Asp.Net Mvc和Asp.Net WebForm实际上共用一套ASP.NET请求管道

UrlRoutingModule是在System.Web程序集下,并不是在Mvc程序集里面,本身在.NETFrameWork框架中就有这个路由类,同时实现IHttpModule接口,那么它肯定有个Init方法.

【深入ASP.NET原理系列】--Asp.Net Mvc和Asp.Net WebForm实际上共用一套ASP.NET请求管道

 

可以看到它往我们的请求application对象,也就是我们的请求管道的第7个事件(PostResolveRequestCache

)上注册了一个方法.如下

 

 1 public virtual void PostResolveRequestCache(HttpContextBasecontext)
 2 
 3 {
 4 
 5     RouteData routeData= this.RouteCollection.GetRouteData(context);
 6 
 7    if (routeData != null)
 8 
 9     {
10 
11        IRouteHandler routeHandler = routeData.RouteHandler;
12 
13        if (routeHandler == null)
14 
15        {
16 
17            throw newInvalidOperationException(string.Format(CultureInfo.CurrentCulture,SR.GetString("UrlRoutingModule_NoRouteHandler"), new object[0]));
18 
19        }
20 
21        if (!(routeHandler is StopRoutingHandler))
22 
23        {
24 
25            RequestContext requestContext = new RequestContext(context, routeData);
26 
27            context.Request.RequestContext = requestContext;
28 
29            IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);
30 
31            if (httpHandler == null)
32 
33            {
34 
35                 object[] args = new object[] {routeHandler.GetType() };
36 
37                 throw newInvalidOperationException(string.Format(CultureInfo.CurrentUICulture,SR.GetString("UrlRoutingModule_NoHttpHandler"), args));
38 
39            }
40 
41            if (httpHandler is UrlAuthFailureHandler)
42 
43            {
44 
45                 if(!FormsAuthenticationModule.FormsAuthRequired)
46 
47                 {
48 
49                     throw newHttpException(0x191, SR.GetString("Assess_Denied_Description3"));
50 
51                 }
52 
53                UrlAuthorizationModule.ReportUrlAuthorizationFailure(HttpContext.Current,this);
54 
55            }
56 
57            else
58 
59            {
60 
61                context.RemapHandler(httpHandler);
62 
63            }
64 
65        }
66 
67     }
68 
69 }
View Code

相关文章: