Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of .NET MyMVC Framework implementing Action

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces. NET MyMVC framework implementation of Action example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

In the GetHandler method of AjaxHandlerFactory, you will finally create an ActionHandler, which is a HttpHandler, which will be called in step 15 of the pipeline.

Note: AjaxHandlerFactory's GetHandler method is called in step 10, and step 12 is preparing Session (non-in-process mode), so you must decide how to use Session before step 12.

All Action code is executed in ActionHandler:

Internal class ActionHandler: IHttpHandler {internal InvokeInfo InvokeInfo; public void ProcessRequest (HttpContext context) {/ / invoke the core utility class and execute 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"); / / call method object result = ExecuteActionInternal (context, vkInfo); / / set OutputCache OutputCacheAttribute outputCache = vkInfo.GetOutputCacheSetting (); if (outputCache! = null) outputCache.SetResponseCache (context) / / the result returned by the processing method IActionResult executeResult = result as IActionResult; if (executeResult! = null) {executeResult.Ouput (context);} else {if (result! = null) {/ / normal type result context.Response.ContentType = "text/plain"; context.Response.Write (result.ToString ()) } internal static object ExecuteActionInternal (HttpContext context, InvokeInfo info) {/ / prepare the parameters to be passed to the calling method object [] parameters = GetActionCallParameters (context, info.Action); / / call method if (info.Action.HasReturn) return info.Action.MethodInfo.Invoke (info.Instance, parameters); else {info.Action.MethodInfo.Invoke (info.Instance, parameters); return null;}}

I didn't mention the timing of calling SetResponseCache () earlier, but it's right here: after the Action is executed.

Once the OutputCache is set, the return value is processed.

In the previous code, there is another important call:

/ prepare the parameter object [] parameters = GetActionCallParameters (context, info.Action) to be passed to the calling method; thank you for reading this article carefully. I hope the article "sample Analysis of the implementation of Action in the .NET MyMVC Framework" shared by the editor will be helpful to you. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report