Use C # To write a simple CGI program
Text: SunWen (From cshrp.net)
In fact, C # can also be used to write programs similar to CGI. It is also very simple to write, that is, to use System. Console. WriteLine. Check the subsequent program:
Class zzz
{
Public static void Main ()
{
System. Console. WriteLine ("Content-Type: text/html ");
System. Console. WriteLine ("<body bgcolor = blue> ");
System. Console. WriteLine ("<center> <p> ");
System. Console. WriteLine ("<B> Hello to everyone. Its me SunWen <B> ");
System. Console. WriteLine ("</body> ");
}
}
We can see that the output of System. Console. WriteLine is in HTML format, and the console is the web server. We just need to compile this file into EXE file, and then put the corresponding CGI-BIN directory in the web server, you can use it. Here, I use IIS as an example to illustrate the problem.
First of all, you must set the site permission to "scripts and executable files". In this way, you can execute the EXE file under the site directory. Copy the EXE file to the site directory and enterHttp: // localhost/a.exeThe result is displayed. Check whether it is an HTML file?