Detailed explanation of the process of finding Action in MyMVC box

Y2J
Release: 2017-05-17 11:30:31
Original
1890 people have browsed it

First, we need to register MyMVC's HttpHandlerFactory in web.config, which is the entrance to the entire framework.
In the ASP.NET pipeline process, the GetHandler() method will be called, and finally my code has a chance to run!
The first line of code executed by the framework is:

// 根据请求路径,定位到要执行的ActionControllerActionPair pair = UrlParser.ParseAjaxUrl(virtualPath);
Copy after login
public sealed class ControllerActionPair{    public string Controller;    public string Action;}
静态方法UrlParser.ParseAjaxUrl()就是专门用来解析URL并返回ControllerActionPair的:
Copy after login

The code is very simple. The core is actually the regular expression, which extracts the Controller from the URL and the name of the Action depends on it.
As for the use of regular expressions, I think this is a basic skill and will be skipped here.

Let’s look at the second call of AjaxHandlerFactory:

// 获取内部表示的调用信息InvokeInfo vkInfo = ReflectionHelper.GetAjaxInvokeInfo(pair);
Copy after login

The ReflectionHelper class is an internal tool class specifically used for reflection processing. The relevant code for the AjaxAction search process is as follows (note the Comments):

The above is the 4 pieces of code related to AjaxAction search:
1. In the static constructor of ReflectionHelper, I loaded All AjaxControllers.
2. The GetAjaxController method is used to return the type description of a Controller based on its name.
3. The GetAjaxAction method is used to return Action description information based on the type of Controller and the name of the Action to be called.
4. The GetAjaxInvokeInfo method is used to convert the ControllerActionPair description obtained from the AjaxHandlerFactory into more specific description information.

In the code, the search process of Action adopts delayed loading mode. To save the collection of Action description information, I use threadsafetyHashtable

[Related recommendations]

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

2. ASPFree Video Tutorial

3. Entry-level .NET MVC Example

4. . NET MyMVC framework detailed explanation of the process of executing Action

5. .NET MyMVC framework tutorial on how to assign values ​​to methods

6. .NET MyMVC framework tutorial on processing return values

The above is the detailed content of Detailed explanation of the process of finding Action in MyMVC box. 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