


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!

To start C#.NET development, you need to: 1. Understand the basic knowledge of C# and the core concepts of the .NET framework; 2. Master the basic concepts of variables, data types, control structures, functions and classes; 3. Learn advanced features of C#, such as LINQ and asynchronous programming; 4. Be familiar with debugging techniques and performance optimization methods for common errors. With these steps, you can gradually penetrate the world of C#.NET and write efficient applications.

The relationship between C# and .NET is inseparable, but they are not the same thing. C# is a programming language, while .NET is a development platform. C# is used to write code, compile into .NET's intermediate language (IL), and executed by the .NET runtime (CLR).

C#.NET is still important because it provides powerful tools and libraries that support multiple application development. 1) C# combines .NET framework to make development efficient and convenient. 2) C#'s type safety and garbage collection mechanism enhance its advantages. 3) .NET provides a cross-platform running environment and rich APIs, improving development flexibility.

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.

C# and .NET adapt to the needs of emerging technologies through continuous updates and optimizations. 1) C# 9.0 and .NET5 introduce record type and performance optimization. 2) .NETCore enhances cloud native and containerized support. 3) ASP.NETCore integrates with modern web technologies. 4) ML.NET supports machine learning and artificial intelligence. 5) Asynchronous programming and best practices improve performance.

C#.NETissuitableforenterprise-levelapplicationswithintheMicrosoftecosystemduetoitsstrongtyping,richlibraries,androbustperformance.However,itmaynotbeidealforcross-platformdevelopmentorwhenrawspeediscritical,wherelanguageslikeRustorGomightbepreferable.

The programming process of C# in .NET includes the following steps: 1) writing C# code, 2) compiling into an intermediate language (IL), and 3) executing by the .NET runtime (CLR). The advantages of C# in .NET are its modern syntax, powerful type system and tight integration with the .NET framework, suitable for various development scenarios from desktop applications to web services.

C# is a modern, object-oriented programming language developed by Microsoft and as part of the .NET framework. 1.C# supports object-oriented programming (OOP), including encapsulation, inheritance and polymorphism. 2. Asynchronous programming in C# is implemented through async and await keywords to improve application responsiveness. 3. Use LINQ to process data collections concisely. 4. Common errors include null reference exceptions and index out-of-range exceptions. Debugging skills include using a debugger and exception handling. 5. Performance optimization includes using StringBuilder and avoiding unnecessary packing and unboxing.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool