Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment.GetEnvironmentVariable won't find variable value

Why won't Environment.GetEnvironmentVariable("variableName") get a variable's value if the call is made from within a webMethod hosted on IIS and it will work if I call it from a console application on the same machine?

Where do I set up those variables to be visible to IIS web services? Should I use the second parameter from Environment.GetEnvironmentVariable(name, target) to get it?

It is actually really simple:

[WebMethod(Description = "Gets the environment variable value.")] public string GetEnvironmentVariable() {     return Environment.GetEnvironmentVariable("VARIABLE_NAME_HERE"); } 

And by the way, VARIABLE_NAME_HERE is set at the system and user level.

like image 242
Lemmerich Avatar asked Oct 05 '12 22:10

Lemmerich


People also ask

How do you find the variable value of an environment?

To display the values of environment variables, use the printenv command. If you specify the Name parameter, the system only prints the value associated with the variable you requested.

How do I get environment variables in robot framework?

Robot Framework uses the ${} syntax to refer to variables, and %{} to refer to environment variables. We are using the value of the variable when calling the Capture Page Screenshot keyword.

How do I enable environment variables?

On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable.

How do I get environment variables in .NET core?

Open project properties by right clicking on the project in the solution explorer and select Properties. This will open properties page. Click on Debug tab and you will see Environment Variables as shown below. You may change the value as per your need.


1 Answers

Restarting Visual Studio fixed it for me (guessing IIS Express also caches these values).

like image 191
Branden Barber Avatar answered Sep 19 '22 18:09

Branden Barber