什么是ASP.NET MVC控制器的寿命是多少? [英] What is the lifetime of a ASP.NET MVC Controller?

查看:76
本文介绍了什么是ASP.NET MVC控制器的寿命是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发我的MVC应用程序的过程中,我在想,一个控制器类的生命周期是什么?

I'm in the process of developing my MVC application and I was thinking, What is the lifetime of a controller class?

当它获得创建?如何单个控制器的多个实例有哪些?什么是局部变量的含义是什么?当它销毁?

When does it get created? How many instances of a single controller are there? what are the implications of local variables? when is it destroyed?

我敢肯定有一个很好的链接在互联网上的某处左右浮动,但我的谷歌福找不到它。

I'm sure there is a good link somewhere floating around on the internet, but my google-fu couldn't find it.

推荐答案

斯蒂芬·瓦尔特有很大的<一个href=\"http://stephenwalther.com/blog/archive/2008/03/18/asp-net-mvc-in-depth-the-life-of-an-asp-net-mvc-request.aspx\">article在请求的生命周期由MVC框架正在处理。

Stephen Walther has a great article on the life-cycle of a request being handled by the MVC Framework.

下面是从他的文章的顶部提取物,它接着详细介绍了每个步骤

Here's a extract from the top of his article, it goes on to explain each step in detail:

生命周期的步骤概述

有当你从一个ASP.NET MVC网站的请求时发生五个主要步骤:

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

1。该RouteTable创建

这第一步只发生一次先启动一个ASP.NET应用程序时。在RouteTable URL映射到处理程序。

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

2。该UrlRoutingModule截获请求

这第二个步骤内,只要您拨打一个请求。该UrlRoutingModule截获每个请求,并创建和执行正确的处理程序。

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

3。该MvcHandler执行

的MvcHandler创建的控制器,通过所述控制器的ControllerContext,并执行该控制器

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

4。控制器执行

控制器确定哪个控制器的方法来执行,生成的参数的列表,并执行该方法

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

5。的的RenderView方法被称为

通常情况下,一个控制器方法调用的RenderView()来呈现内容返回给浏览器。该Controller.RenderView()方法委托其工作于特定视图引擎

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控制器的寿命是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆