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.
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.
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.
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.
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.
Restarting Visual Studio fixed it for me (guessing IIS Express also caches these values).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With