Web.config and environnement var

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • skevtaz
    New Member
    • May 2009
    • 4

    Web.config and environnement var

    Hi,

    I knew that with ASP.NET 2.0, we couldn't use environnement variables in the web.config.

    But I don't find any ressources for this case on 3.5.

    Is it possible now ?

    thx
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    The 3.5 Framework is an "add-on" to the 2.0 Framework.
    Therefore, you access variables stored in the web.config the same way using both Frameworks.

    The web.config file is used to configure your web application.You can also store data in it that is used by the entire application (like connection strings and other variables). It's not meant to store system environment variables though.

    You should be able to access environment variables in your C# or VB code using the GetEnvironmentV ariable method that is part of the System.Environm ent namespace:
    Code:
    System.Environment.GetEnvironmentVariable(...)

    Comment

    • skevtaz
      New Member
      • May 2009
      • 4

      #3
      Thanks you for your response.

      I know that. I don't want to store Environment Variable in my web.config. We got deployement problems based on somes absolut and relative paths configure in the web.config.
      Our architecture is a little complex and deployment on our several envirronment is not a clean procedure.

      So, I just want that : <add key="xxx" value="%Environ ment{PATH}\XXXX \YYYY"></add>

      And I don't need to get it at runtime by some code.

      Thx

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Do you have a setup program to help install the application?
        In that case, you should be writing the key into the web.config using the setup application.

        Comment

        • skevtaz
          New Member
          • May 2009
          • 4

          #5
          yes we got MSI to deploy some blocks (DLL) of our application but we don't use it for the web site.

          But I notice the tips :)

          tx

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Or you could just add the key as:
            "<add key="xxx" value="\XXXX\YY YY"></add>"

            And in your C# or .NET code use append the "%Environment{P ATH}%" to the key when you require it using the System.Environm ent.GetEnvironm entVariable() method.

            Comment

            • skevtaz
              New Member
              • May 2009
              • 4

              #7
              As I say on my previous reply, I can't because it's for a deployment issue.

              We test "policy injection" but it's seems it's too complex for our goal.

              We think about testing the Web Platform installer which is in RC now. Do U use it ?

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Originally posted by skevtaz
                We think about testing the Web Platform installer which is in RC now. Do U use it ?
                No sorry I've never used it before.

                Comment

                Working...