在看這篇Fun with Http Headers in ASP.NET MVC Action Filters的時候,提到了 Roni Schuetz在codeplex上建立的一個項目ASP.NET MVC Action Filters。計劃在5月10日推出第一個版本。 專案計劃包含的Action Filter:
- Action filter for creating easy REST API with JSON and XML
- Action filter for logging scenarios
- Action filter for microsoft health monitoring
- Action filter for client caching
- Action filter for client compression
- Action filter for server caching
- Action filter for controller execution time measurement
簡要介紹一下Action Filter:Action Filter作為一個可以應用到Controller Action(或者是整個controller)上的屬性(Attribute),改變Action執行的行為。ASP.NET MVC Framework包括幾種Action Filter:
- OutputCache – 在指定的時間內緩衝Controller Action的輸出。
- HandleError – 處理Controller Action發生錯誤的情況。
- Authorize – 通過制定的使用者或者角色約束存取權限。
你同時可以建立自己的Action Filter,比如說要實現一個自訂的驗證系統,那麼可能需要建立一個自訂的Action Filter,或者說當你需要改變Controller Action返回的View data的時候,也可以通過建立自訂Action Filter實現。
關於Action Filter的具體內容可參考 理解ASP.NET MVC Framework Action Filters(翻的)。