<appsettings>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kenneth

    #1

    <appsettings>

    Hi,

    In web.config I have an appsettings:

    <appSettings>
    <add key="constring"
    value="Server=l ocalhost;UID=sa ;PWD=secret;Dat abase=myDB" />
    </appSettings>

    This is for my developing machine.

    Every time I deploy this web.config to the production
    server I forget to change the UID and PWD which are
    different on this machine.

    Is there a way to write some code that detects which
    server you're on so the server picks the right UID and PW`?

    /Kenneth
  • Teemu Keiski

    #2
    Re: &lt;appsettings &gt;

    Of course you can't put running code into the web.config. That wasn't what I
    mentioned.

    Point really was that you'd put machinenames into <appSettings> as keys (or
    as part of keys say "connectionStri ng_MACHINENAME" ) for connection strings
    and then by using Environment.Mac hineName your code solves in which machine
    it is running and picks the correct config setting ("connectionStr ing_" &
    Environment.Mac hineName)

    --
    Teemu Keiski
    MCP,Designer/Developer
    Mansoft tietotekniikka Oy


    AspInsiders Member, www.aspinsiders.com
    ASP.NET Forums Moderator, www.asp.net
    AspAlliance Columnist, www.aspalliance.com


    "Kenneth" <kenneth.philp@ chello.se> kirjoitti viestissä
    news:095f01c366 ec$67b9f120$a60 1280a@phx.gbl.. .
    Kiitos paljon Teemu for a fast reply,

    Environment.Mac hineName can't be used in web.config, only
    in code in aspx doc.

    If you have to test new things in web.config and test it
    in dev machine then you'll end upp with a mess if you have
    to rewrite it.

    /Kenneth
    [color=blue]
    >-----Original Message-----
    >Environment.Ma chineName for example returns the NetBios[/color]
    name of the machine.[color=blue]
    >Perhaps you could name the key (for both machines[/color]
    respectively) based on[color=blue]
    >that.
    >
    >Other option would be just deploy the web.config on[/color]
    production machine once[color=blue]
    >with the setting and then just don't rewrite it. ;-)
    >
    >--
    >Teemu Keiski
    >MCP,Designer/Developer
    >Mansoft tietotekniikka Oy
    >http://www.mansoft.fi
    >
    >AspInsiders Member, www.aspinsiders.com
    >ASP.NET Forums Moderator, www.asp.net
    >AspAlliance Columnist, www.aspalliance.com
    >
    >
    >"Kenneth" <kenneth.philp@ chello.se> kirjoitti viestissä
    >news:08f501c36 6e9$16a21540$a4 01280a@phx.gbl. ..[color=green]
    >> Hi,
    >>
    >> In web.config I have an appsettings:
    >>
    >> <appSettings>
    >> <add key="constring"
    >>[/color][/color]
    value="Server=l ocalhost;UID=sa ;PWD=secret;Dat abase=myDB" />[color=blue][color=green]
    >> </appSettings>
    >>
    >> This is for my developing machine.
    >>
    >> Every time I deploy this web.config to the production
    >> server I forget to change the UID and PWD which are
    >> different on this machine.
    >>
    >> Is there a way to write some code that detects which
    >> server you're on so the server picks the right UID and[/color][/color]
    PW`?[color=blue][color=green]
    >>
    >> /Kenneth[/color]
    >
    >
    >.
    >[/color]


    Comment

    • John Saunders

      #3
      Re: &lt;appsettings &gt;

      "Kenneth" <kenneth.philp@ chello.se> wrote in message
      news:08f501c366 e9$16a21540$a40 1280a@phx.gbl.. .[color=blue]
      > Hi,
      >
      > In web.config I have an appsettings:
      >
      > <appSettings>
      > <add key="constring"
      > value="Server=l ocalhost;UID=sa ;PWD=secret;Dat abase=myDB" />
      > </appSettings>[/color]

      Kenneth,

      You can do the following in web.config:

      <?xml version="1.0" encoding="utf-8" ?>
      <configuratio n>
      <appSettings file="user.conf ig">
      <add key="Key" value="Value" />
      </appSettings>
      </configuration>

      Then, in a file called user.config in the same folder as web.config, you can
      put the following (notice there's no "<configuration >" tag):

      <?xml version="1.0" encoding="utf-8" ?>
      <appSettings>
      <add key="Key" value="Override value" />
      </appSettings>

      If there is no user.config in the same folder, then the web.config settings
      are used.

      --
      John Saunders
      Internet Engineer
      john.saunders@s urfcontrol.com


      Comment

      Working...