简体   繁体   中英

Intercept ASP.NET MVC 4 response generation

What I need to do is execute some code before the MVC executes the controller and after it finishes generating the View. Is there any way to do this?

I need to integrate the MVC application with an existing cache system, so:

  • before executing the controller, instantiate a cache.
  • after the view was generated, destroy the cache.

Action Filter Attributes enable you to inject code interceptors into the request of a MVC controller that can execute before and after a Controller or its Action methods execute.

For more detail, see: Understanding Filter Interceptors by Scott Guthrie

明显的答案是global.asax中的Application_BeginRequestApplication_EndRequest还是我缺少什么?

If you want to hook into page events, you'll probably want to implement your own WebViewPage and WebViewPage classes. Specifically, you'll want to decorate the Execute method. Phil Haack has a blog post on how to do this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM