Life cycle analysis of asp.net MVC preview (i.)

Source: Internet
Author: User
Tags reflector

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;


      }


    }





}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.