Web.config and environment variables. Please help!

Discussion in 'ASP .Net' started by =?Utf-8?B?b3R0bw==?=, May 12, 2006.

  1. 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!
     
    =?Utf-8?B?b3R0bw==?=, May 12, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?b3R0bw==?=

    Greg Young Guest

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

    Cheers,

    Greg Young
    MVP - C#
    "otto" <> wrote in message
    news:...
    > 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!
     
    Greg Young, May 12, 2006
    #2
    1. Advertising

  3. =?Utf-8?B?b3R0bw==?=

    Mark Rae Guest

    "otto" <> wrote in message
    news:...

    > 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!
     
    Mark Rae, May 12, 2006
    #3
  4. =?Utf-8?B?b3R0bw==?=

    Mark Rae Guest

    "otto" <> wrote in message
    news:...

    > 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...)
     
    Mark Rae, May 12, 2006
    #4
  5. 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

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


    "otto" <> wrote in message
    news:...
    > 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!
     
    Karl Seguin [MVP], May 12, 2006
    #5
  6. =?Utf-8?B?b3R0bw==?=

    Mark Rae Guest

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

    > 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...?
     
    Mark Rae, May 12, 2006
    #6
  7. 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" <> wrote in message
    news:%23crK%...
    > "Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
    > net> wrote in message news:...
    >
    >> 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...?
    >
     
    Karl Seguin [MVP], May 12, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page