Martin Heller
Contributing Writer

Iron Python for ASP.NET

analysis
Feb 9, 20073 mins

I mentioned my affinity for Python on my first Weblog entry, at the end of last year. I had intended to tell you about the Iron Python for ASP.NET CTP in my second entry, but it mysteriously stopped working for me before I could write about it. It turns out that disabling Iron Python for ASP.NET was an unintended side effect of the Visual Studio SP1 installation, which also caused other mayhem on my Visual

I mentioned my affinity for Python on my first Weblog entry, at the end of last year. I had intended to tell you about the Iron Python for ASP.NET CTP in my second entry, but it mysteriously stopped working for me before I could write about it. It turns out that disabling Iron Python for ASP.NET was an unintended side effect of the Visual Studio SP1 installation, which also caused other mayhem on my Visual Studio 2005 instance. By the time I had fixed all that and reinstalled Iron Python for ASP.NET I was distracted by the AJAX subversion exploit.

I recently went back and looked at the Iron Python for ASP.NET CTP, and was impressed with what has actually been accomplished with that project. It’s not just that you can code server-side ASP.NET Web logic very simply in Python, as in this Global.py from the Iron Python Personal Web site starter site:

from System import *
from System.Web import *
from System.Web.Security import *

def Application_Start():
    SiteMap.SiteMapResolve += AppendQueryString
    if not Roles.RoleExists('Administrators'): Roles.CreateRole('Administrators')
    if not Roles.RoleExists('Friends'): Roles.CreateRole('Friends')

def AppendQueryString(sender, e):
    node = SiteMap.CurrentNode
    if node is not None:
        node = node.Clone(True)
        qs = e.Context.Request.QUERY_STRING
        if len(qs) > 0:
            node.Url += '?' + qs
            if node.ParentNode is not None:
                node.ParentNode.Url += '?' + qs
    return node

It’s also not just that you can write code behind standard-looking ASP.NET pages in Python, and that much of what you already know about Python and ASP.NET just carries over.

No, it’s even more impressive than that. What this team has done is to extend the ASP.NET model from static compiled languages to dynamic languages, as explained in David Ebbo’s white paper on the subject. They basically scrapped the CodeDOM model used for static compiled languages, and extended the idea of no-compile pages. It sounds like a paradox, but they’ve created no-compile pages that support scripting languages with a change to the PageParserFilter API, which gives external code a hook into the parser. They have also added a custom HTTP module, and a custom base class for scripting pages.

One thing they haven’t done is to support Web services. That turned out to be hard, and it’s not clear when or even whether they’ll come up with a solution. Another thing that they haven’t done in the CTP, but which I hope to see in a future drop, is to write full Visual Studio IntelliSense support for Python. Stay tuned.

Martin Heller

Martin Heller is a contributing writer at InfoWorld. Formerly a web and Windows programming consultant, he developed databases, software, and websites from his office in Andover, Massachusetts, from 1986 to 2010. From 2010 to August of 2012, Martin was vice president of technology and education at Alpha Software. From March 2013 to January 2014, he was chairman of Tubifi, maker of a cloud-based video editor, having previously served as CEO.

Martin is the author or co-author of nearly a dozen PC software packages and half a dozen Web applications. He is also the author of several books on Windows programming. As a consultant, Martin has worked with companies of all sizes to design, develop, improve, and/or debug Windows, web, and database applications, and has performed strategic business consulting for high-tech corporations ranging from tiny to Fortune 100 and from local to multinational.

Martin’s specialties include programming languages C++, Python, C#, JavaScript, and SQL, and databases PostgreSQL, MySQL, Microsoft SQL Server, Oracle Database, Google Cloud Spanner, CockroachDB, MongoDB, Cassandra, and Couchbase. He writes about software development, data management, analytics, AI, and machine learning, contributing technology analyses, explainers, how-to articles, and hands-on reviews of software development tools, data platforms, AI models, machine learning libraries, and much more.

More from this author