The Polyglot Web

Web Coding in C#

Unfortunately, C# and Mono are not installed on this server. Functions are disabled.

C# is a compiled language. However, it does not compile to native code like C++ does, but to byte code (the common runtime language) that runs on a virtual machine. Because C# does not compile to native code, I invoke the C# interpreter from the command line in a separate executable shell script file, for example this one, which is named images.cgi:

mono images.exe

Because I'm developing and deploying on a Mac, I don't have access to the Visual Studio compiler that is widely available on Windows. So instead, I use the Mono system to compile and execute the code. When compiling, it is sometimes necessary to to specify the libraries; C# calls this referencing the library. Each of my projects has a library of utility functions available in a module called common. In C#, you can compile a class to exe instead of DLL, and still reference its methods from other classes. I wrote this simple compile script to make sure my outside references get included in each class that needs them:

dmcs $1.cs -r:common.exe

I named the script makd and I use it like this. This example compiles the source.cs file.

./makd source

CGI from C#

CGI variables are available as environment variables. In C#, these can be obtained from standard provided methods: Environment.GetEnvironmentVariable(), etc.