Register global action filters in modules?

Topics: Writing modules
Jul 9, 2012 at 4:18 PM

Hi there,

is there a way to register global action filters inside of a module?

Regards
Thomas

Coordinator
Jul 9, 2012 at 4:30 PM

Sure, look for FilterProvider and IActionFilter subclasses.

Jul 9, 2012 at 4:41 PM

Thanks for the quick reply. I already had a look at them and also at some filters like ThemeFilter. But I couldn't find any way to register filters globally so they are used by all actions. Could you provide me one or two more hints that get me into right direction?!

Cheers
Thomas

Coordinator
Jul 9, 2012 at 4:46 PM

ThemeFilter is used by all actions because it implements IActionFilter. It is also registered automatically in Orchard because has it inherits from FilterProvider, it implements IDependency. 

Create a class that inherits from FilterProvider and implements IActionFilter. Put it in any module, done.

Jul 9, 2012 at 5:02 PM

Great, that did the trick! Hopefully I will be able to give something back to community in form of a new module soon :)