Copy Code code as follows:
Mvchandler:ihttphandler
void Ihttphandler.processrequest (HttpContext HttpContext)
{
This. ProcessRequest (HttpContext);
}
protected virtual void ProcessRequest (HttpContext HttpContext)
{
HttpContextBase base2 = new Httpcontextwrapper (HttpContext);
This. ProcessRequest (BASE2);
}
protected internal virtual void ProcessRequest (HttpContextBase HttpContext)
{
IController Controller;
Icontrollerfactory Factory;
This. Processrequestinit (HttpContext, out of controller, out factory);
Try
{
Controller. Execute (this. RequestContext);
}
Finally
{
Factory. Releasecontroller (Controller);
}
}
Copy Code code as follows:
Controller:ControllerBase:IController
void Icontroller.execute (RequestContext requestcontext)//------>controller
{
This. Execute (RequestContext);
}
protected virtual void Execute (RequestContext requestcontext)//------>controllerbase
{
if (RequestContext = null)
{
throw new ArgumentNullException ("RequestContext");
}
if (Requestcontext.httpcontext = null)
{
throw new ArgumentException (Mvcresources.controllerbase_cannotexecutewithnullhttpcontext, "RequestContext");
}
This. Verifyexecutecalledonce ();
This. Initialize (RequestContext);
using (Scopestorage.createtransientscope ())
{
This. Executecore ();
}
}
protected override void Executecore ()//------>controller
{
This. Possiblyloadtempdata ();
Try
{
String requiredstring = this. Routedata.getrequiredstring ("action");
if (!this. Actioninvoker.invokeaction (base. ControllerContext, requiredstring))//public iactioninvoker actioninvoker {get; set;}
{
This. Handleunknownaction (requiredstring);
}
}
Finally
{
This. Possiblysavetempdata ();
}
}
Copy Code code as follows:
Controlleractioninvoker:iactioninvoker
Public virtual bool Invokeaction (ControllerContext ControllerContext, String actionname)
{
if (ControllerContext = null)
{
throw new ArgumentNullException ("ControllerContext");
}
if (string. IsNullOrEmpty (ActionName))
{
throw new ArgumentException (Mvcresources.common_nullorempty, "actionname");
}
Controllerdescriptor Controllerdescriptor = this. Getcontrollerdescriptor (ControllerContext);
Actiondescriptor Actiondescriptor = this. Findaction (ControllerContext, Controllerdescriptor, ActionName);
if (Actiondescriptor = null)
{
return false;
}
FilterInfo filters = this. Getfilters (ControllerContext, actiondescriptor);
Try
{
AuthorizationContext context = this. Invokeauthorizationfilters (ControllerContext, filters. Authorizationfilters, Actiondescriptor);
if (context. Result!= null)
{
This. Invokeactionresult (ControllerContext, context. result);
}
Else
{
if (controllerContext.Controller.ValidateRequest)
{
ValidateRequest (ControllerContext);
}
idictionary<string, object> parametervalues = this. Getparametervalues (ControllerContext, actiondescriptor);
ActionExecutedContext context2 = this. Invokeactionmethodwithfilters (ControllerContext, filters. Actionfilters, Actiondescriptor, parametervalues);
This. Invokeactionresultwithfilters (ControllerContext, filters. Resultfilters, Context2. result);
}
}
catch (ThreadAbortException)
{
Throw
}
catch (Exception Exception)
{
Exceptioncontext CONTEXT3 = this. Invokeexceptionfilters (ControllerContext, filters. Exceptionfilters, exception);
if (!CONTEXT3. exceptionhandled)
{
Throw
}
This. Invokeactionresult (ControllerContext, Context3. result);
}
return true;
}
protected virtual void Invokeactionresult (ControllerContext controllercontext, ActionResult ActionResult)
{
Actionresult.executeresult (ControllerContext);
}
Copy Code code as follows:
ActionResult
public override void Executeresult (ControllerContext context)
{
if (context = null)
{
throw new ArgumentNullException ("context");
}
if (string. IsNullOrEmpty (this. ViewName))
{
This. ViewName = context. Routedata.getrequiredstring ("action");
}
Viewengineresult result = null;
if (this. View = = null)
{
result = this. Findview (context); Viewengineresult
This. View = result. View; IView interface
}
TextWriter output = context. HttpContext.Response.Output;
ViewContext viewcontext = new ViewContext (context, this. View, this. ViewData, this. TempData, output);
This. View.render (viewcontext, Output);
if (Result!= null)
{
Result. Viewengine.releaseview (context, this.) View);
}
}