Ironpython for ASP. NET CTP

Source: Internet
Author: User

[Original article] ironpython for ASP. NET CTP
[Original article publication date] Thursday, November 16,200

I wrote about ironpython V1.0 a few months ago. Ironpython is an implementation of the python dynamic language on the. NET platform. It supports an interactive console that supports full dynamic compilation and allows Python programmers to easily access all. Net libraries while maintaining full compatibility with the Python language.

Ironpython provides an excellent example of how the. NET programming language can take advantage of the Dynamic Language features added to the. NET 2.0 CLR last year. For example, CLR features such as "lightweight encoding generation" can now allow dynamic languages to quickly compile and JIT source code in the memory (giving you a fast running speed without having to generate one. DLL file ). CLR 2.0 also has the ability to recycle the JIT code. This means that you can dynamically adjust the type at runtime without leaking the generated encoding.

Last week, we released a very cool CTP that provides ironpython integration support in ASP. NET and Visual Web Developer Express (of course free of charge. After the installation is complete, you can use python as your language selection when creating new projects and pages, and easily use dynamic language script support:

Ironpython for ASP. after installing. Net CTP, Visual Studio/Visual Web Developer will use ASP. the net project provides support for Inline code and code-behind Web pages, syntax highlighting, WYSIWYG designer, and complete debugging support. You can also use it to create independent Python module files in the app_script folder and use them for the entire website.

The easiest way to explore Python usage is to select a File> New website menu item, and then create a Python version of the personal starter kit sample Website (note that the extension below is. PY background code file ):

The above personal starter kit Python sample provides a cool way to start learning python. It also utilizes some dynamic language functions provided by python, as well as the added ironpython development team and ASP. net.

For example, the photos. aspx web page allows administrators to upload new photos to the album. This is achieved through a formview control using the templated insert mode UI, as shown in the following code:

<Asp: formview id = "formview1" defaultmode = "insert" oniteminserting = "formview1_iteminserting" runat = "server">
<Insertitemtemplate>

Enter photo: <asp: fileupload id = "photofile "... />
Enter caption: <asp: textbox id = "photocaption "... />

....

</Insertitemtemplate>
</ASP: formview>

In a strongly typed language, you usually need to use the findcontrol () method of formview1 to enter its template to obtain the reference of the fileupload or Textbox Control, and then forcibly convert the reference to the type of the returned object to use these objects. However, in a dynamic language like python, you can write the following encoding in your photos. aspx. py background code file:

Import photomanager

Def formviewincluiteminserting (sender, e ):

Caption = formview1.photocaption. Text
Bytes = formview1.photofile. filebytes

If Len (bytes) = 0:
E. Cancel = true
Else:
Photomanager. addphoto (request. albumid, caption, bytes)

You only need to write formview1.photocaption to access the child control in the template, and then directly reference its sub-attribute. This technology can also be used in templated controls like datalist, repeater, and wizard. Wonderful!

How to learn more about ironpython

Check the ironpython for ASP. NET homepage to learn more about ironpython for ASP. net ctp. You can also read the wonderful white paper written by David ebbo here, which describes the changes made to ASP. NET analyzer to better support dynamic languages and compilation.

Finally, if you want to learn more about ironpython, I suggest you watch the wonderful broadcast of JOD Udell's interview with Jim hugunin in August (with a demonstration in it ). Jim wrote some cool demos on site, including using ironpython to create a WPF calculator application integrated with the Speech API. Then he demonstrated how to refactor the key code that affects performance from Python to a strongly typed language like C #, and how the two work seamlessly. Now you can use the same technology on ironpython and ASP. NET.

I hope this article will help you,

Scott

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.