Home > Article > Backend Development > Detailed explanation of the process of executing Action in .NET MyMVC framework
In the GetHandler method of AjaxHandlerFactory, an ActionHandler will finally be created, which is an HttpHandler, which will be called in the 15th step of the pipeline (quoting the sequence in the blog [Write your own service framework with Asp.net] ).
Note: The GetHandler method of AjaxHandlerFactory is called in step 10. Step 12 is preparing the Session (non-in-process mode). Therefore, the use of Session must be decided before step 12.
All Action codes are executed in ActionHandler:
internal class ActionHandler : IHttpHandler{ internal InvokeInfo InvokeInfo; public void ProcessRequest(HttpContext context) { // 调用核心的工具类,执行Action ActionExecutor.ExecuteAction(context, this.InvokeInfo); }
The implementation process of ExecuteAction is as follows:
internal static void ExecuteAction(HttpContext context, InvokeInfo vkInfo) { if( context == null ) throw new ArgumentNullException("context"); if( vkInfo == null ) throw new ArgumentNullException("vkInfo"); // 调用方法 object result = ExecuteActionInternal(context, vkInfo); // 设置OutputCache OutputCacheAttribute outputCache = vkInfo.GetOutputCacheSetting(); if( outputCache != null ) outputCache.SetResponseCache(context); // 处理方法的返回结果 IActionResult executeResult = result as IActionResult; if( executeResult != null ) { executeResult.Ouput(context); } else { if( result != null ) { // 普通类型结果 context.Response.ContentType = "text/plain"; context.Response.Write(result.ToString()); } } }internal static object ExecuteActionInternal(HttpContext context, InvokeInfo info) { // 准备要传给调用方法的参数 object[] parameters = GetActionCallParameters(context, info.Action); // 调用方法 if( info.Action.HasReturn ) return info.Action.MethodInfo.Invoke(info.Instance, parameters); else { info.Action.MethodInfo.Invoke(info.Instance, parameters); return null; } }
Didn’t I mention the timing of calling SetResponseCache() before? , this opportunity is here: after executing the Action.
After setting the OutputCache, it is time to process the return value.
In the previous code, there is another important call:
// 准备要传给调用方法的参数object[] parameters = GetActionCallParameters(context, info.Action);
[Related recommendations]
1. Special recommendation: "php Programmer Toolbox" V0.1 version download
3. Entry-level .NET MVC example
4. Detailed explanation of the process of finding Action in the MyMVC box
5 . .NET MyMVC framework tutorial on how to handle return values
6. .NET MyMVC framework tutorial on how to assign values to methods
The above is the detailed content of Detailed explanation of the process of executing Action in .NET MyMVC framework. For more information, please follow other related articles on the PHP Chinese website!