A Simple IronPython ActionFilter for ASP.NET MVC

ASP.NET MVC is the all new web framework for .NET inspired by frameworks like Rails and Django. There are a few examples of IronPython and IronRuby integration with ASP.NET MVC but the dynamic languages support is incomplete. Harry Pierson has blogged about at least one of the problems.

Despite this there are various places where IronPython can be integrated with ASP.NET MVC, as demonstrated by a new article (with example code for download) on Code Voyeur:
There are times when an action filter has transient logic that will change frequently. Logging, authorization or request sanitizing rules are examples of filters that may require extensive configuration to achieve needed flexibility.

Rather than create several filters that make excessive use of appSettings, it is possible to use the Dynamic Language Runtime and script files to achieve the same result. This article will demonstrate how to create a filter that uses a simple convention to map action filter hooks to functions in IronPython script files. Like other CodeVoyeur articles, this one assumes the choice of a statically typed language for core application logic has already been made.

The PyFilter class will be the core file that performs the execution of the IronPython code. It will override each of the four virtual action filter methods from the ActionFilterAttribute base class.

Comments

Popular posts from this blog

Extending Abobe Flash Player and AIR with Python and Ruby

Should Python Projects Support IronPython and Jython?

Further Adventures of the Debugger