[Mono-list] Compiling C# program with Request object

Robert Jordan robertj at gmx.net
Wed Jul 9 18:02:51 EDT 2008


theallan wrote:
> Hello all,
> 
> I want to write a little CGI program that I can run under IIS, and I'm some
> what stumped - here is what I have:
> 
> public class Test 
> { 
>         static void Main() 
>         {
> 		Console.Write( "Content-type: text/html\n\n" );
>                 System.Console.WriteLine(
> System.Web.HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"] ); 
>         } 
> } 
> 
> Which is all well can good - it compiles with "gmcs -out:text.exe test.cs
> -r:System.Web". But then I transfer the .exe file to my Windows machine and
> try to run it as a CGI program I get:
> 
> Unhandled Exception: System.NullReferenceException: Object reference not set
> to an instance of an object.

Well, a HttpContext is only available to ASP.NET applications.

> So the question is, how can I compile a C# application with Mono using the
> 'Request' object and have it available under a IIS CGI environment. Or
> should I be accessing the CGI variables in some different manner?

Get them from the environment (see the CGI specs) or resort to ASP.NET.

Robert



More information about the Mono-list mailing list