Do asp.net webform development are known, ASP. NET has a complex lifecycle, learning asp.net mvc requires a deep understanding of its lifecycle. Today from CodePlex download asp.net Preview 2 source code, there are two assemblies routing and abstractions did not publish, but the two assemblies are not many classes, you can use the NET decompile tool reflector untie to see, Unfortunately, the two assemblies were developed using the. NET 3.5, with many of the features of C # 3.0, Reflector VS2008.
ASP.net mvc begins his execution process through HttpModule (urlroutingmodule)
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing" />
The code is as follows:
namespace System.Web.Routing
{
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using System.Web;
using System.Web.Resources;
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level=aspnethostingpermissionlevel.minimal), AspNetHostingPermission (SecurityAction.LinkDemand, level=aspnethostingpermissionlevel.minimal)]
public class Urlroutingmodule:ihttpmodule
{
private static readonly Object _requestdatakey = new Object ();
private System.Web.Routing.RouteCollection _routecollection;
protected virtual void Dispose ()
{
}
protected virtual void Init (HttpApplication application)
{
application. Postresolverequestcache + = new EventHandler (this. Onapplicationpostresolverequestcache);
application. Postmaprequesthandler + = new EventHandler (this. Onapplicationpostmaprequesthandler);
}
private void Onapplicationpostmaprequesthandler (object sender, EventArgs e)
{
httpcontextbase context = new HttpContextWrapper2 ((HttpApplication) sender). context);
this. Postmaprequesthandler (context);
}
private void Onapplicationpostresolverequestcache (object sender, EventArgs e)
{
httpcontextbase context = new HttpContextWrapper2 ((HttpApplication) sender). context);
this. Postresolverequestcache (context);
}
public virtual void Postmaprequesthandler (HttpContextBase context)
{
requestdata data = (requestdata) context. Items[_requestdatakey];
if (data!= null)
{
context. RewritePath (data. Originalpath);
context. Handler = data. HttpHandler;
}
}
public virtual void Postresolverequestcache (HttpContextBase context)
{
Routedata Routedata = this. Routecollection.getroutedata (context);
if (routedata!= null)
{
Iroutehandler routehandler = Routedata.routehandler;
if (Routehandler = null)
{
throw new InvalidOperationException (string. Format (CultureInfo.CurrentUICulture, Routingresources.urlroutingmodule_noroutehandler, new object[0]);
}
RequestContext requestcontext = new RequestContext (context, routedata);
IHttpHandler HttpHandler = Routehandler.gethttphandler (RequestContext);
if (HttpHandler = null)
{
throw new InvalidOperationException (string. Format (CultureInfo.CurrentUICulture, Routingresources.urlroutingmodule_nohttphandler, new object[] { Routehandler.gettype ()));
}
requestdata data2 = new RequestData ();
data2. Originalpath = context. Request.path;
data2. HttpHandler = HttpHandler;
context. Items [_requestdatakey] = data2;
context. RewritePath ("~/urlrouting.axd");
}
}
void Ihttpmodule.dispose ()
{
this. Dispose ();
}
void Ihttpmodule.init (HttpApplication application)
{
this. Init (application);
}
Public System.Web.Routing.RouteCollection routecollection
{
get
{
if (this._routecollection = null)
{
this._routecollection = routetable.routes;
}
return this._routecollection;
}
Set
{
this._routecollection = value;
}
}
}