Search results for 'C# CGI Sample'. 2 post(s) found.

  1. 2007/08/27 Simple C# CGI working on Apache
  2. 2007/08/27 How to send binary data through C# CGI app?
2007/08/27 13:39

Simple C# CGI working on Apache


Simple program to demonstarte the power of c# on the Net. This program require web server e.g(java web server ,apache etc).

Hello.cs
class zzz
{
  public static void Main()
  {
    System.Console.WriteLine("Content-Type:text/html\n");
    System.Console.WriteLine("");
    System.Console.WriteLine("");
    System.Console.WriteLine("Hello to everyone. It's me Kurapa Chunun Kang");
    System.Console.WriteLine("");
  }
}



Compile the class Hello.cs. This will give u a exe file i.e Hello.exe.Put this file in the server's CGI-bin directory. for e.g if u have java server installed in C drive than the place to put the Hello.exe is c:/javawebserver/CGI-bin/" your file i.e hello.exe".
Copy the file Hello.exe to CGI-bin directory. now open the browser window and put the url http://localhost:8080/CGI-bin/Hello.exe considering your server is running at 8080 port.

Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 03:26 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 12:23 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:44 delete

    moneyideas

2007/08/27 13:05

How to send binary data through C# CGI app?


Following example implemented binary data downloading.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace cscgi
{
  class CsCGI
  {
    private static string dbgString = "id=1234&pic=123.gif";
    private List<string> lstKeys = new List<string>();
    private List<string> lstVals = new List<string>();
    static void Main(string[] args)
    {
      CsCGI app = new CsCGI();
      ParseParams(app);
      string sID = GetParam(app, "id");
      string sFile = GetParam(app, "pic");
      try
      {
        FileStream fs = new FileStream(sFile, FileMode.Open);
        BinaryReader brFile = new BinaryReader(fs, Encoding.UTF8);
        byte[] bBuff = new byte[fs.Length];
        brFile.Read(bBuff, 0, (int)fs.Length);
        string sBuff = Encoding.ASCII.GetString(bBuff);
        // if it's just text file, change binary/plain to text/html
        Console.Write("Content-Type: binary/plain\n");
        Console.Write("Content-Length: " + fs.Length.ToString());
        Console.Write("\n\n");
        Console.Write(sBuff);
      }
      catch (Exception e)
      {
        Console.Write(e.Message + "\n");
      }
      finally
      {
        //
      }
    }

    private static void ParseParams(CsCGI app)
    {
      //string queryString = Environment.GetEnvironmentVariable("QUERY_STRING");
      string queryString = dbgString;
      string[] sParams = queryString.Split('&');
      string[] sParamsSeperated;
      for (int i = 0; i < sParams.Length; i++)
      {
        sParamsSeperated = sParamsIdea.Split('=');
        app.lstKeys.Add(sParamsSeperated[0]);
        app.lstVals.Add(sParamsSeperated[1]);
      }
    }

    private static string GetParam(CsCGI app, string key)
    {
      int idx = app.lstKeys.BinarySearch(key);
      if (idx >= 0)
        return app.lstVals[idx];
      return "";
    }
  }
}


If you are using Apache and wanna test it just put the EXE in the cgi-bin folder under Apache's directory. Also note that the parameters are static just for this example.
Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 02:25 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 10:53 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:44 delete

    moneyideas