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.
Useful Links
Strings
- How to get base filename
- Path.GetFileName method
- Char.ToUpper method
- String.Replace method
- String.Format method
- Regex.Replace method
- HttpUtility.UrlDecode method
- String.Compare method
- How to convert between hexadecimal strings and numeric types
- What is the C# equivalent of the chr() function?
- String.Substring method
- String.Split method
Files
MySQL
- How to I add a reference to the MySQL connector?
- IDbConnection Interface
- MySQL C# Tutorial
- SqlCommand.ExecuteReader method
- Installing Connector/Net on Unix with Mono
- System.Data namespace
Deployment
- Understanding CGI with C#
- How to compile c# code as library instead of an executable
- Running a mono program without typing in 'mono foo.exe'
- System.Data DLL
- Running C# program compiled with Mono in Linux
- Mono 4.0.2 Release Notes