Web.config and environment variables. Please help!

G

Guest

Hi, all:
I would like to know one thing: Is it possible to access an environment
variable (like PATH) from web.config file? Something like this:
<appSettings>
<add key="name" value="%Environment{PATH}\Shared"></add>
</appSettings>

or

<add key="name" value="${PATH}\Shared"></add>
or anything else?

I think it´s not possible the access to system or environment variables from
inside web.config, but I need to be absolutely sure.

Thanks a lot for your help!
 
G

Greg Young

No, you would have to translate these in your code that read in the value.

Cheers,

Greg Young
MVP - C#
 
M

Mark Rae

I think it´s not possible the access to system or environment variables
from
inside web.config, but I need to be absolutely sure.

Thanks a lot for your help!
 
M

Mark Rae

I think it´s not possible the access to system or environment variables
from
inside web.config, but I need to be absolutely sure.

It's not possible

(Sorry for the empty post previously...)
 
K

Karl Seguin [MVP]

No.

But what you can do is encapsulate that logic inside a function:

public sealed ConfigurationManager
{
private ConfigurationManager(){}
public static string Path
{
get
{
return Configuration.AppSettings["name"].Replace("{PATH}",
Environment.GetEnvironmentVariable("Path");
}
}
}

as an example...

Karl
 
M

Mark Rae

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message
No.

But what you can do is encapsulate that logic inside a function:

public sealed ConfigurationManager
{
private ConfigurationManager(){}
public static string Path
{
get
{
return Configuration.AppSettings["name"].Replace("{PATH}",
Environment.GetEnvironmentVariable("Path");
}
}
}

as an example...

Yes of course, but what value does that add? Why not just interrogate the
environment variable when required...?
 
K

Karl Seguin [MVP]

It helps encapsulate the logic. A lot of people would have done the
replacement each time on all of their pages. Apologies with assuming you
didn't know this...you never know what people do and don't know :)

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


Mark Rae said:
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message
No.

But what you can do is encapsulate that logic inside a function:

public sealed ConfigurationManager
{
private ConfigurationManager(){}
public static string Path
{
get
{
return Configuration.AppSettings["name"].Replace("{PATH}",
Environment.GetEnvironmentVariable("Path");
}
}
}

as an example...

Yes of course, but what value does that add? Why not just interrogate the
environment variable when required...?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top