MVC4和页面生命周期? [英] MVC4 and page life cycle?

查看:159
本文介绍了MVC4和页面生命周期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET MVC4没有一个页面生命周期像普通的aspx页面做的。一个人如何使用preINIT,初始化,在MVC4 prerender?

ASP.NET MVC4 doesn't have a page life cycle like regular aspx pages do. How does one make use of preinit, init, prerender in MVC4?

有没有MVC4任何类型的生命周期?

Is there any type of life cycle in MVC4?

推荐答案

没有,没有页面生命周期本身(因为没有页对象),但有一个请求处理管道,这通常会事像这样的:

No, there is no page life cycle per se (because there is no 'page' object), but there is a request processing pipeline, which usually goes something like this:


  1. 传入的请求被拾起 System.Web.Routing.UrlRoutingModule ,它使用请求URL映射请求到控制器的操作方法。

  2. 相应的控制器被实例化

  3. 模型绑定和可能出现输入验证

  4. OnActionExecuting 的控制器和/或行动的行动过滤器 - 方法被调用

  5. 的操作方法本身调用

  6. 任何 OnActionExecuted OnResultExecuting 的行动过滤器 - 方法被调用

  7. 的ActionResult 的操作方法(通常是的ViewResult 这使得HTML)执行返回。

  8. 任何 OnResultExecuted 的行动过滤器 - 方法被调用。

  1. Incoming request is picked up by the System.Web.Routing.UrlRoutingModule which uses the request url to map the request to a controller action method.
  2. The appropriate controller is instantiated
  3. Model binding and input validation may occur
  4. The OnActionExecuting-methods of action filters on the controller and/or action are invoked
  5. The action method itself is invoked
  6. Any OnActionExecuted and OnResultExecuting-methods of action filters are invoked
  7. The ActionResult returned by the action method (typically, a ViewResult which renders HTML) is executed.
  8. Any OnResultExecuted-methods of action filters are invoked.

上面的列表只是一个草图:

The list above is just a rough sketch:

路由的:
传入的​​请求到MVC控制器的操作方法的映射是其本身的故事。请参见 ASP.NET路由在MSDN上获取更多信息。

动作过滤器的:
有行动过滤器授权,输出缓存,错误处理等等,所有这些都在一定的时间运行。这一次,请参见过滤在ASP.NET MVC MSDN上,获取更多信息。

Action filters: There are action filters for authorization, output caching, error handling etc., all of which run at a certain time. This time see Filtering in ASP.NET MVC on MSDN for more info.

ASP.NET 的:
而且,当然还是有所有href=\"http://msdn.microsoft.com/en-us/library/bb470252(v=vs.100).aspx\" rel=\"nofollow\">传统的ASP.NET的的。因此,HTTP模块一样好老 System.Web.Security.FormsAuthenticationModule System.Web.Caching.OutputCacheModule ,可还在参加一个请求的处理。

ASP.NET: And, of course there's still all the traditional ASP.NET application events. Hence, HTTP modules like good old System.Web.Security.FormsAuthenticationModule and System.Web.Caching.OutputCacheModule, may still take part in the processing of a request.

如果你想真正深入到细节,从的 codePLEX 。大部分你是什么之后会在 System.Web.Mvc.ControllerActionInvoker 类,其中,尽管可怕的名字,是不是太难懂了。

If you want to really delve into the details, download the source code for the ASP.NET web stack from CodePlex. Much of what you are after will be in the System.Web.Mvc.ControllerActionInvoker class, which, despite the scary name, isn't too hard to follow.

请参阅德扬的答案的链接,凝聚了太多的一个很好的图。

See Dejan's answer for a link to a good diagram that sums up much of this.

这篇关于MVC4和页面生命周期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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