Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

IronPython Web Site Support System

Visual Studio 2005
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

IronPython Web site support is a Language Services implementation and a collection of templates and registration attributes that allow IronPython to be used as a web programming language. The Web site templates are in the WebSiteProject\Templates folder, and the registration attributes are defined in the PythonProject\RegistrationAttributes folder.

For more information on Web site templates, see Web Site Support Templates. For more information on Web site registration attributes, see Web Site Support Attributes (C#).

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices.  Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

Language service support for IronPython as a contained web language is located in the IronPython LanguageService project. The ProvideIntellisenseProvider attribute selects the PythonIntellisenseProvider as the Intellisense provider for the language. PythonIntellisenseProvider implements IVsIntellisenseProject, which is created on demand to provide language services.

PythonIntellisenseProvider handles references and calls the language compiler when a Web page with code is requested but is not cached.

NoteNote

There is currently no support for generating event handlers from the designer.

The language compiler used to compile web pages must be registered with ASP.NET. This registration is done with the <compiler> Element in the web.config file of a new Web site application:

<system.codedom>  <compilers>    <compiler language="py;IronPython" extension=".py"       type="IronPython.CodeDom.PythonProvider, IronPython,       Version=1.0.2391.18146, Culture=neutral,       PublicKeyToken=b03f5f7f11d50a3a" />  </compilers></system.codedom>
NoteNote

Because of the internal treatment of white space, Intellisense and ASP.NET currently do not work together. You can write code that works for one, but not the other. In .aspx.py dependent files, use spaces only and no tabs. In .aspx Web pages, begin code render inline expression blocks (<%= %>) on the left margin. <script> tags may not contain IronPython code, and code render inline code tags (<% %>) do not work. See the procedures below for more information.

To run the IronPython Web site support sample you must first install two IronPython binaries into the global assembly cache. See the procedure below for more information.

To install the IronPython binaries

  1. Open the Visual Studio Command Prompt window and navigate to this folder:

    [Visual Studio SDK installation path]\VisualStudioIntegration\Common\Assemblies\

  2. At the command prompt, type the following lines:

    gacutil -i ironmath.dllgacutil -i ironpython.dll
    

To build and run the sample

  1. Open the IronPython.sln solution in [Visual Studio SDK installation path]\VisualStudioIntegration\Samples\IronPythonIntegration\.

  2. On the Build menu, click Rebuild Solution.

  3. At the command prompt in the Visual Studio Command Prompt window, type >devenv /installvstemplates.

  4. In Visual Studio, press F5 to start Visual Studio from the experimental hive.

To see the sample's functionality

  1. On the File menu, click New Web site to display the New Web site dialog box.

  2. In the Language list, select IronPython. Select ASP.NET Web site, and then click OK..

    The new solution appears in Solution Explorer, the web page Default.aspx appears in the code editor, and the project properties appear in the Properties window.

  3. Press F5 to build and run the Web site under the ASP.NET Development Server.

    The HTML tags are compiled and rendered by IronPython. Nothing is displayed at this time.

  4. Close the ASP.NET Development Server.

  5. Add this line to the body of the Default.aspx Web page. Be sure to begin it at the left margin:

    <body>
        <form id="form1" runat="server">
        <div>
    <%= self.GetText() %>
        </div>
        </form>
    </body>
    
  6. Open the Default.aspx.py file in the code editor.

  7. On the Tools menu, click Options. Navigate to Text Editor, All Languages, Tabs page.

  8. Select Insert spaces, then click OK. New tabs become spaces.

  9. Add these lines to the _Default class:

    class _Default(System.Web.UI.Page):
        "Description of Class"
        
        def GetText(self):
            return "Hello, world"
    
  10. Press F5 to build and run the Web site under the ASP.NET Development Server.

    The text "Hello, world" appears.

Demonstrates

See Also

Other Resources

IronPython Samples

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.