IronPython for ASP has been released for some time now, after looking at the official samples, I believe there are some concerns about the full use of IronPython development in an ASP. After all, it is only a CTP version, and lacks the support of Visual Studio intellisence, and there are some shortcomings in debugging.
Today, however, I did some experiments and found that I could introduce IronPython in an existing C # ASP. NET project without affecting the functionality of the original program, so that we could use C # in a hybrid, IronPython two languages to develop ASP.
The concrete steps are this:
1. First, we build a C # ASP. NET website Project , or WEB application project, in the usual way. Both of these I have experimented with and can support IronPython. I'll take the WEB application Project for example.
2. Then, add a reference to the IronPython.dll, IronMath.dll, Microsoft.Web.IronPython.dll three DLLs. these three DLLs can be found in the official release of the IronPython for ASP.
3. Add some support for the IronPython language in Web. config.
<Configuration>
<appSettings/>
<connectionStrings/>
<system. Web>
<!--Modify the Parser of the page to support IronPython -
<pagesPageparserfiltertype= "Microsoft.Web.IronPython.UI.NoCompileCodePageParserFilter"CompilationMode= "Auto" />
<AuthenticationMode= "Windows" />
<compilationDebug= "false">
<Assemblies>
<AddAssembly= "Microsoft.Web.IronPython, version=1.0.0.0, Culture=neutral, publickeytoken=31bf3856ad364e35"/>
</Assemblies>
</compilation>
<!--Add HttpModule -
<httpmodules>
<Addname= "Dynamiclanguagehttpmodule"type= "Microsoft.Web.IronPython.DynamicLanguageHttpModule"/>
</httpmodules>
<!--add an HTTP handler for handling Python programs -
<httphandlers>
<AddPath= "web_*.py"verb="*"type= "Microsoft.Web.IronPython.SimpleHandler" />
<AddPath= "*.py"verb="*"type= "System.Web.HttpForbiddenHandler"Validate= "true" />
</httphandlers>
</system.web>
</Configuration>
I made a little comment in the above file. For a detailed schematic description, please refer to my translation and summary whitepaper. Want to know the detailed principle of friends, you can use Reflector view Microsoft.Web.IronPython.dll, there will be a lot of harvest.
4. Add the App_script folder under the project.
Then you can add some. py files under here. It works just like App_Code.
In this demo, I wrote a simple foo.py:
defFoo ():
return 'Foo'
5. Now, you can create a page with IronPython. But since we are currently building a C # type of project, we have some actions that need to be manually adjusted.
First add a common WebForm, such as ipy1.aspx, and then delete the. aspx.cs and. aspx.designer.cs files. Below we need to make some adjustments to Ipy1.aspx's Page Directive:
<%@ Page Language="IronPython"codebehind="ipy1.aspx.py" %>
Next, we manually add the background code file ipy1.aspx.py to this page, it is important to note that the ASPX page and the background code file created with IronPython are not inherited from the class. There is also a detailed description of this in the White paper.
The contents of this file are as follows:
fromSystemImportRandom
ImportFoo
defPage_Load ():
Response.Write (foo. Foo ())
Here we refer to the functions in the foo.py module that we just defined.
6.
Open IE to see:
At the same time, programs written in C # under this project are not affected by any of the following:
As we can see from the above example, in the case where we are still not comfortable with IronPython for ASP, we can use this method to simplify some of the General page development process by gradually using IronPython in existing applications! (No doubt, IronPython is simple, isn't it?) :) )
Here is an example attached
Code。
Source: http://www.cnblogs.com/RChen/archive/2006/12/02/cs_ipy_aspnet.html
Incrementally use IronPython to develop your ASP.