Share via


Obtaining permission to access environment variables.

Question

Wednesday, November 30, 2005 10:12 PM

I wrote my C# program to function as a .cgi for use with IIS. However, when I attempt to run this code "System.Environment.GetEnvironmentVariable("SERVER_NAME")" I get a permission exception. How can I allow my application to get this environment variable?

All replies (1)

Tuesday, December 13, 2005 8:40 PM

I had this same issue when I tried to run an exe from IIS.  I tried to add an environment variable with Process.StartInfo.EnvironmentVariable.Add("SSDIR") and I sort of got the same issue.  For some reason the "SSDIR" could not be found no matter what I did.  Eventually I looked at the tast manager to see what User was running my application when I called it from IIS.  It turned out to be my computer name with an anonymous password.  So what I did was go into IIS and clicked on properties on my cgi-bin folder.  Went to "Directory Services" and edited the anonymous access and authentication control.  I set the username (i.e. "domainname\username") and password and unchecked "Allow IIS to control password".  This way when the application is run, the user of the application is set to whomever you wish.  I think then you will be able to get environment variables from there.  Hope this helps.