码迷,mamicode.com
首页 > Web开发 > 详细

HTTP Modules versus ASP.NET MVC Action Filters

时间:2015-12-02 20:28:51      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

from:http://odetocode.com/blogs/scott/archive/2011/01/17/http-modules-versus-asp-net-mvc-action-filters.aspx

Monday, January 17, 2011

ASP.NET MVC has action filters, while ASP.NET has HTTP modules. Inside their respective processing pipelines, these abstractions serve similar purposes, and I‘ve heard the following question a few times:

When should I write an HTTP module and when should I write an action filter?

If you are creating an MVC application then I‘ll almost always recommend going with an action filter instead of an HTTP module. This is my recommendation even if the functionality you are creating is generic enough to work from inside a module (in other words, it doesn‘t depend on MVC specific pipeline stages, like the pre and post processing of action invocation). Filters are closely aligned with the MVC infrastructure and vocabulary, and filters are the first thing someone will look for when they want to see how you‘ve implemented cross-cutting functionality in MVC.

On the other hand, an HTTP module is something you can reuse in any type of ASP.NET application. Witness the flexibility of elmah - just drop an assembly in the bin directory, tweak a config file, and wait for elmah to record errors across an entire application. This configurable flexibility isn‘t something you can do with filters out of the box, but we’ll see tomorrow how easy it is to add.

HTTP Modules versus ASP.NET MVC Action Filters

标签:

原文地址:http://www.cnblogs.com/imust2008/p/5014018.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!