views:

145

answers:

3
+1  Q: 

Compile C# as CGI

How do you compile a C# program as CGI to run in the cgi-bin of a LAMP/Linux/Apache server?

A: 

Maybe, you could use a very simple wrapper script, e.g., with bash, that itself executes your C# program with mono in the normal way. e.g.:

#!/usr/bin bash

/usr/bin/opt/mono myprogram.exe $@

(Of course, just using Apache with mod_mono is a much better solution, if you can.)

Stewart
+1  A: 

Nothing special is required - just compile the application as normal with Mono's gmcs compiler.

For more information on integration, check out these two links:

http://www.mono-project.com/ASP.NET

and this one for CGI specifically:

http://www.mono-project.com/CGI

tgiphil
I agree with Stewart that Apache with mod_mono is a much better solution than CGI or FASTCGI.
tgiphil
this looks like it's the solution. will try this tomorrow, but just wondering has anyone tried compiling C#/.NET into CGI?
ina
this seems to work for some basic apps, but not all libraries seem encapsulated for more complex apps (still text-based though)..
ina
A: 

You usually compile C programs using the compiler on the server, often the gnu compiler. If this is the complier you are using then;

gcc -o <name_of_output_file>.cgi <name_of_source_file>

Whatever you name the file you need to give it the extension .cgi All You have to do then is to move it to the cgi-bin folder, remember to set the permissions of the program, usually for cgi stuff you use 755;

chmod 755 <name_of_file>

This is how I do it for C, C# I imagine is the same.

Rooneyl