You cannot (easily) inject runtime values to attributes. This is how attributes work in C# - you can only pass constant values of certain types. You can read more about it here.
In order to achieve desired functionality in Orchard you need to split your code into two components:
- a marker attribute class you put on your action
- an action filter class inheriting from
FilterProvider
and implementingIActionFilter
The way it works is that you put an attribute on some action and then use the action filter to check existence of that attribute (using filterContext.ActionDescriptor.GetCustomAttributes(...)
). If an attribute exists, do your stuff.
There are lots of examples of this technique in Orchard core. Check eg. the ThemedAttribute
and ThemeFilter
action filter classes.