Previous Next

Thread: Access CGI environment variables

Last post 08-07-2008 2:12 AM by ksingla. 3 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (4 items)

Sort Posts:

  • 08-04-2008, 4:50 PM

    • theallan
    • Not Ranked
    • Joined on 08-04-2008, 8:36 PM
    • Posts 2

    Access CGI environment variables

    Hello all,

    I'm writing a little CGI C# program which needs to read environment variables such as QUERY_STRING in order to do it's required processing. To do this I was using System.Environment.GetEnvironmentVariable(), which works great on the CLI, but as soon as I have it under IIS CGI I get:

    Unhandled Exception: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

    So the question is, how do I go about getting QUERY_STRING (etc) from a CGI application in IIS?

    Thanks
    Allan
  • 08-05-2008, 2:01 AM In reply to

    • ksingla
    • Top 10 Contributor
    • Joined on 06-14-2006, 3:02 AM
    • Redmond, WA
    • Posts 547

    Re: Access CGI environment variables

    Hi Allan,

    Either you need to run worker process as a user which has EnvironmentPermission or grant EnvironmentPermission to your CGI explicitly. You can follow instructions specified here.

    Thanks,
    Kj

  • 08-05-2008, 4:11 AM In reply to

    • theallan
    • Not Ranked
    • Joined on 08-04-2008, 8:36 PM
    • Posts 2

    Re: Access CGI environment variables

    Brilliant - thanks for the link Kj! Out of interest - the first line of the article says "Not that I recommend CGI" - could anyone tell me if there is a better way to deploy my application in .Net? Basically it is a text file interpreter - take a text file, munge it around a bit, and then fire it out. With CGI in IIS I can have any file with a particular extension (say .allan) processed by the compiled binary. Is there a better way of doing this in IIS? Thanks again Allan
  • 08-07-2008, 2:12 AM In reply to

    • ksingla
    • Top 10 Contributor
    • Joined on 06-14-2006, 3:02 AM
    • Redmond, WA
    • Posts 547

    Re: Access CGI environment variables

    Writing a handler might be a better to do this. If you are a C# person, search for IHttpHandler and you will find plenty of samples on internet.

    Thanks,
    Kj

Page 1 of 1 (4 items)
Page view counter