gpt4 book ai didi

asp.net-mvc - ASP.NET MVC Controller 的生命周期是多长?

转载 作者:行者123 更新时间:2023-12-03 05:31:10 25 4
gpt4 key购买 nike

我正在开发 MVC 应用程序,我在想, Controller 类的生命周期是多长?

什么时候创建的?单个 Controller 有多少个实例?局部变量有什么含义?什么时候销毁?

我确信互联网上有一个很好的链接,但我的 google-fu 找不到它。

最佳答案

Stephen Walther 有一个很棒的article关于 MVC 框架处理的请求的生命周期。

以下是他文章顶部的摘录,其中详细解释了每个步骤:

Overview of the Lifecycle Steps

There are five main steps that happen when you make a request from an ASP.NET MVC website:

1. The RouteTable is Created

This first step happens only once when an ASP.NET application first starts. The RouteTable maps URLs to handlers.

2. The UrlRoutingModule Intercepts the Request

This second step happens whenever you make a request. The UrlRoutingModule intercepts every request and creates and executes the right handler.

3. The MvcHandler Executes

The MvcHandler creates a controller, passes the controller a ControllerContext, and executes the controller.

4. The Controller Executes

The controller determines which controller method to execute, builds a list of parameters, and executes the method.

5. The RenderView Method is Called

Typically, a controller method calls RenderView() to render content back to the browser. The Controller.RenderView() method delegates its work to a particular ViewEngine

关于asp.net-mvc - ASP.NET MVC Controller 的生命周期是多长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2355139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com