Home > Backend Development > C#.Net Tutorial > Detailed explanation of the process of executing Action in .NET MyMVC framework

Detailed explanation of the process of executing Action in .NET MyMVC framework

Y2J
Release: 2017-05-17 11:29:07
Original
2562 people have browsed it

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);
    }
Copy after login

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;
    }
}
Copy after login

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);
Copy after login

[Related recommendations]

1. Special recommendation: "php Programmer Toolbox" V0.1 version download

2. ASP free video tutorial

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template