ASP.NET (tutorial) - vilinski/nemerle GitHub Wiki

Preparations

In order to use Nemerle in your ASP.NET pages you first need to add the following lines to your web.config file under <configuration><system.web> (or merge them if you already have a compilation section).

<compilation debug=“true”>
         <compilers>
           <compiler 
             language="n;nemerle;Nemerle" extension=".n" warningLevel="1" 
             type="Nemerle.Compiler.NemerleCodeProvider, Nemerle.Compiler, Version=x.x.x.xxxx, Culture=neutral, PublicKeyToken=5291d186334f6101" 
             compilerOptions="/lib:path/to/nemerle/installation"
            />
         </compilers>
</compilation> 

Replace the x.x.x.xxxxx with the version provided by gacutil -l Nemerle.Compiler. They must match exactly. Also replace path/to/nemerle/installation with the path to the place where Nemerle was installed (one holding ncc.exe and Nemerle.Macros.dll).

In mono, you can edit the machine.config file to get the same effect globally.

Example page

Now you can create test.aspx with following content:

<%@ Language=“Nemerle” %>

         <script runat="server">
           Page_Load(_ : object, _ : EventArgs) : void {
             Message.Text = $"You last accessed this page at: $(DateTime.Now)";
           }

           EnterBtn_Click(_ : object, _ : EventArgs) : void 
           {
             Message.Text = $"Hi $(Name.Text), welcome to ASP.NET!";
           }
         </script>
<html>

             <form runat=server>

                 <div style="font-family: Verdana;"> 

                    <p>
                        Please enter your name: <asp:TextBox id="Name" runat="server" /> 
                        <asp:Button id="EnterBtn" text="Enter" OnClick="EnterBtn_Click" runat="server" />
                    </p>
                    <p>
                      <asp:Label id="Message"  runat="server" />
                    </p>

                 </div>

              </form>
</html> 

And everything should work fine. This scenario was tested with xsp and mod_mono on mono 1.1.6, please let us know how it works on MS.NET + IIS.
update from 07.08.2006 I made it work under IIS + MS.NET, but not exact abovementioned code. I failed to make it recognize <asp:* > tags. I guess, some additional work is needed.

Using a separate file for code is also possible and may be preferable in larger examples. This may be done by creating a file test.n for the code.

 using System; 
 using System.Web.UI; 
 using System.Web.UI.WebControls;

public partial class Test : Page 
{
          protected Page_Load(_ : object, _ : EventArgs) : void
          {
            Message.Text = $"You last accessed this page at: $(DateTime.Now)";
          }
          protected EnterBtn_Click(_ : object, _ : EventArgs) : void
          {
            Message.Text = $"Hi $(Name.Text), welcome to ASP.NET!";
          }
}

and then removing the script section of test.aspx and replacing the top line with

<%@ Language=“Nemerle” CodeFile=“test.n” Inherits=“Test” %\> 
⚠️ **GitHub.com Fallback** ⚠️