[杂] ASP.NET MVC 之 Route To MvcHandler

首先,本文参考了不少东东,仅供Q_L_H自己使用,ZZ自己负责。先上一张全家福:

dd695917.fig02(en-us)

HttpModules and HttpHandlers

ASP.NET MVC 是 HttpHandler.

UrlRoutingModule 是 HttpModule, 在web.config里面注册。

UrlRoutingModule → MvcRouteHandler

MvcRouteHandler → MvcHandler

IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext)

   {

     return this.GetHttpHandler(requestContext);

   }



protected virtual IHttpHandler GetHttpHandler(RequestContext requestContext)

    {

      requestContext.HttpContext.SetSessionStateBehavior(this.GetSessionStateBehavior(requestContext));

      return (IHttpHandler) new MvcHandler(requestContext);

    }

MvcHandler → IController

private void ProcessRequestInit(HttpContextBase httpContext, out IController controller, out IControllerFactory factory)

    {

      HttpContext current = HttpContext.Current;

      if (current != null)

      {

        bool? nullable = ValidationUtility.IsValidationEnabled(current);

        if ((!nullable.GetValueOrDefault() ? 0 : (nullable.HasValue ? 1 : 0)) != 0)

          ValidationUtility.EnableDynamicValidation(current);

      }

      this.AddVersionHeader(httpContext);

      this.RemoveOptionalRoutingParameters();

      string requiredString = this.RequestContext.RouteData.GetRequiredString("controller");

      factory = this.ControllerBuilder.GetControllerFactory();

      controller = factory.CreateController(this.RequestContext, requiredString);

      if (controller != null)

        return;

      throw new InvalidOperationException(string.Format((IFormatProvider) CultureInfo.CurrentCulture, MvcResources.ControllerBuilder_FactoryReturnedNull, new object[2]

      {

        (object) factory.GetType(),

        (object) requiredString

      }));

    }

参考文章:

http://www.codeproject.com/Articles/595520/MvcRouteHandler-and-MvcHandler-in-ASP-NET-MVC-Fram

http://beletsky.net/2011/06/inside-aspnet-mvc-route-to-mvchanlder.html

http://msdn.microsoft.com/en-us/magazine/dd695917.aspx

你可能感兴趣的:(asp.net)