ASP.NET is the implementation of server-side code based on .NET to create dynamic web pages. Mono does support ASP.NET with some additional configuration F# can also be used to create dynamic web content.
As we need multiple elements to work correctly to program ASP.NET in F’ we will go step-by-step to ensure that each element works on your installation as well.
First lets test your mono installation with a simple C# ASP.NET program. Do the following steps
1. Create a directory ‘csharp-hello’ in your favorite place and change into it
~> md csharp-hello ~> cd csharp-hello ~/csharp-hello>
2. Create a file index.aspx
<%@ Page Language="C#" AutoEventWireup="true" Debug=true %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<% Response.Write("Hello World says C#"); %>
</body>
</html>
3. Start the web server xsp2 integrated together with mono to test
~/csharp-hello> xsp2 xsp2 Listening on address: 0.0.0.0 Root directory: ~/Projekte/Fsharp/asp.net/csharp-hello Listening on port: 8080 (non-secure) Hit Return to stop the server.
4. Start your web browser and point it to ‘http://localhost:8080′.
Now lets do the same in F#, we do need some additional configuration to write ASP.NET applications in F’.
1. Create a directory ‘hello’ in your favorite place, change into it and create a directory ‘bin’
~> md hello ~> cd hello ~/hello>
2. We need a web.config file to tell mono how to compile F# code. Create the file ‘web.config’ in the directory ‘hello’.
<?xml version="1.0"?> <configuration> <system.web> <compilation debug="true"> <assemblies> <add assembly="FSharp.Compiler.CodeDom, Version=2.0.0.0, Culture=neutral,PublicKeyToken=a19089b1c74d0809"/> </assemblies> <compilers> <compiler language="F#;f#;fs;fsharp" extension=".fs" type="Microsoft.FSharp.Compiler.CodeDom.FSharpAspNetCodeProvider, FSharp.Compiler.CodeDom, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a19089b1c74d0809"/> </compilers> </compilation> </system.web> </configuration>
3. Additionally, we need a directory bin which contains the F# compiler. A symbolic link is also sufficient.
~/hello> md bin ~/hello> cd bin ~/hello/bin> ln -s /usr/local/lib/FSharp-2.0.0.0/bin/FSharp.Compiler.CodeDom.dll . ~/hello/bin> cd .. ~/hello>
4. Now you may start the web server
~/hello> xsp2 xsp2 Listening on address: 0.0.0.0 Root directory: ~/Projekte/Fsharp/asp.net/hello Listening on port: 8080 (non-secure) Hit Return to stop the server.
5. Open your web browser and point it to ‘http://localhost:8080′
Further reading:



Pingback: Rick Minerich's Development Wonderland : F# Discoveries This Week 10/18/2010
Pingback: ASP.NET Webforms and Event Handling | 2#4u