global-filter

How to disable a global filter in ASP.Net MVC selectively

梦想与她 提交于 2019-11-26 03:54:24
问题 I have set up a global filter for all my controller actions in which I open and close NHibernate sessions. 95% of these action need some database access, but 5% don\'t. Is there any easy way to disable this global filter for those 5%. I could go the other way round and decorate only the actions that need the database, but that would be far more work. 回答1: You could write a marker attribute: public class SkipMyGlobalActionFilterAttribute : Attribute { } and then in your global action filter