Gradually use ironpython to develop your ASP. NET application

Source: Internet
Author: User

Ironpython for ASP. net ctp has been released for some time. After reading the official examples, I believe that for an ASP. NET applicationProgramThere are still some concerns about fully using ironpython for development. After all, it is only the CTP version, and it lacks the support of Visual Studio's intelliisence. It also has some shortcomings in debugging.

However, I did some experiments today and found that the existing ASP. the introduction of ironpython in the net project does not affect the functions of the original program. In this way, we can use both C # And ironpython languages to Develop ASP.. net.

The specific steps are as follows:

1. First, we create a C # ASP. NET Website project in the usual way.Or the web application project. I have done both experiments and can support ironpython. I will take the web application project as an example below.

2. Add references to ironpython. dll, ironmath. dll, and Microsoft. Web. ironpython. dll.These three DLL files can be found in the officially released ironpython for ASP. NET example.

3. Add ironpython support in Web. config.

< Configuration >
< Appsettings />
< Connectionstrings />

System . web >
modify the parser of a page to support ironpython -->
pages pageparserfiltertype =" Microsoft. web. ironpython. UI. nocompilecodepageparserfilter " compilationmode =" Auto " />

<AuthenticationMode= "Windows" />

< Compilation Debug = "False" >
< Assemblies >
< Add Assembly = "Microsoft. Web. ironpython, version = 1.0.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35" />
</ Assemblies >
</ Compilation >

<! -- Add httpmodule -->
< Httpmodules >
< Add Name = "Dynamiclanguagehttpmodule" Type = "Microsoft. Web. ironpython. dynamiclanguagehttpmodule" />
</ Httpmodules >

<! -- Add HTTP handler for processing Python programs -->
< Httphandlers >
< Add Path = "Web _ *. py" Verb = "*" Type = "Microsoft. Web. ironpython. simplehandler"   />
< Add Path = "*. Py" Verb = "*" Type = "System. Web. httpforbiddenhandler" Validate = "True"   />
</ Httphandlers >
</ System. Web >
</ Configuration >

I made some comments in the above file. For a detailed description of the principles, see my translation and abstract White Paper. If you want to learn more about the principles, you can use reflector to view Microsoft. Web. ironpython. dll. There will be a lot of GAINS.

4. Add the app_script folder under the project.

Then you can add some. py files below. It works just like app_code.

In this demo, I wrote a simple Foo. py:

Def Foo ():
Return   ' Foo '

5. Now, you can use ironpython to create a page.However, because the current project is a C # project, we need to manually adjust some actions.
Add a common webform, such as ipy1.aspx, and delete the. aspx. CS and. aspx. Designer. CS files. Below we need to make some adjustments to ipy1.aspx page ctictive:

<% @ Page Language = " Ironpython " Codebehind = " Ipy1.aspx. py "   %>

Next, we will manually attach the background to this pageCodeFile ipy1.aspx. py. Note that the ASPX page created using ironpython is not an inheritance relationship between the background code file. This is also described in detail in the White Paper.
The content of this file is as follows:

From System Import Random
Import Foo

def page_load ():
response. write (FOO. foo ()

the foo. functions in The py module.

6. open IE and check:

at the same time, programs written in C # in this project are not affected:

the preceding example shows that, in ironpython for ASP. net is still not safe enough, you can use ironpython in existing applications to simplify some of the general page development process! (There is no doubt that ironpython is simple, isn't it?)

the Code of the example is attached here.

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.