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

May 17, 2017 am 11:29 AM

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

DJI Osmo Action 5 Pro: Release date mooted as retailer reveals launch pricing that could undercut GoPro Hero 13 Black DJI Osmo Action 5 Pro: Release date mooted as retailer reveals launch pricing that could undercut GoPro Hero 13 Black Sep 04, 2024 am 06:51 AM

DJI has not confirmed any plans to introduce a new action camera yet. Instead, it seems that GoPro will get ahead of its rival this year, having teased that it will introduce two new action cameras on September 4. For context, these are expected to a

New DJI Osmo action camera spotted before probable summer 2024 launch to rival recent GoPro and Insta360 releases New DJI Osmo action camera spotted before probable summer 2024 launch to rival recent GoPro and Insta360 releases Jul 01, 2024 am 09:49 AM

Almost a year has passed since DJI released the Osmo Action 4 (curr. $299 on Amazon). Since then, the company has focused on its other divisions, including new RS camera gimbals. On top of that, it has introduced various drones as well like the Avata

Insta360 Go 3S: New pocketable 4K action camera released weighing just 39 g with Apple Find My support Insta360 Go 3S: New pocketable 4K action camera released weighing just 39 g with Apple Find My support Jun 14, 2024 pm 06:05 PM

Insta360hasreleasedanewactioncamera,itssecondoftheyearaftertheInsta360X4(curr.$499.99onAmazon).Asexpected,thecompanyhasintroducedtheGo3S,anupgradedthatGo3thatadds4Kvideorecordingcapabilities.Specifically,whileInst

Detailed explanation of Action asynchronous operation of Vuex state management Detailed explanation of Action asynchronous operation of Vuex state management Aug 10, 2022 pm 03:29 PM

In some cases, we want to perform some asynchronous operations in Vuex, such as network requests, which must be asynchronous. How to deal with this situation? Let me introduce to you the Action asynchronous operation of Vuex state management. I hope it will be helpful to friends in need. !

GoPro releases new Hero 13 Black action camera with new lens mods alongside curious GoPro Hero GoPro releases new Hero 13 Black action camera with new lens mods alongside curious GoPro Hero Sep 05, 2024 am 06:45 AM

GoPro has now introduced its annual action camera refresh. Unlike in recent years, the company has decided to release two models. However, it has not returned to 360-degree cameras, despite teasing this time last year that it would replace the Max wi

How to implement elasticsearch java client action How to implement elasticsearch java client action May 22, 2023 am 08:43 AM

Most operations in elasticsearch are through corresponding actions, which are in the action package. Its structure is shown in the figure below: The above figure is a partial screenshot of the action package, which corresponds to the actions of each function. The packages of each action are also very similar to index. The implementation of these actions is also very similar. They are all basic self-actions. The following figure shows the inheritance relationship of indexaction: Because these actions do not actually implement the corresponding functions, they are just a proxy, so the implementation is also very simple. Their main function is to provide methods for creating new responses and requests and their corresponding actions.

GoPro Hero: New pocket-sized action camera leaks along with rumoured release date GoPro Hero: New pocket-sized action camera leaks along with rumoured release date Aug 16, 2024 am 09:43 AM

Details of a completely new GoPro action camera has leaked online alongside equivalent information about the Hero 13 Black. Please note that the information contained below is said to originate from an Amazon US listing that has since now been remove

Deal | Amazfit GTR 3 Pro Limited Edition smartwatch with 12-day battery life, GPS and 1,000 nits AMOLED now available for just $125 Deal | Amazfit GTR 3 Pro Limited Edition smartwatch with 12-day battery life, GPS and 1,000 nits AMOLED now available for just $125 Aug 15, 2024 am 11:14 AM

The Amazfit GTR 3 Pro Limited Edition is currently on sale at Amazon for just $124.99, down 40% from its list price of $209.99. Compared to the standard version that has an aluminum case, the Amazfit GTR 3 Pro Limited Edition uses hand-polished stain

See all articles