FubuMVC using ModifyChainAttributes
Let’s take a look at a handy way to quickly modify a FubuMVC behavior chain by simply placing an Attribute on the action method. This technique is handy when you have a one off change you need to make to a specific action and rolling your own site wide convention is too much.
We ran into a problem on a specific API endpoint which supports file uploads where IE9 would barf on a JSON response after uploading a file. In this case the response was not being consumed by the client. No big deal let’s force the output to be XML to ensure that IE9 is happy.
To do this we will need to remove all non XML output formatters from the behavior chain.
Implementing a chain modifying attribute is easy.
- Subclass ModifyChainAttribute.
- Edit the parent behavior chain (via the ActionCall)
You then simply apply your new custom attribute to your action. Take a look at FubuDiagnostics and see the changes to your chain. In this case there is only one output formatter XmlFormatter.