Professional Web Applications Themes

<appsettings> - ASP.NET General

Hi, In web.config I have an appsettings: <appSettings> <add key="constring" value="Server=localhost;UID=sa;PWD=secret;Database =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...

  1. #1

    Default <appsettings>

    Hi,

    In web.config I have an appsettings:

    <appSettings>
    <add key="constring"
    value="Server=localhost;UID=sa;PWD=secret;Database =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
    Kenneth Guest

  2. #2

    Default Re: <appsettings>

    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 "connectionString_MACHINENAME") for connection strings
    and then by using Environment.MachineName your code solves in which machine
    it is running and picks the correct config setting ("connectionString_" &
    Environment.MachineName)

    --
    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" <se> kirjoitti viestissä
    news:095f01c366ec$67b9f120$gbl...
    Kiitos paljon Teemu for a fast reply,

    Environment.MachineName 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
     
    name of the machine. 
    respectively) based on 
    production machine once [/ref]
    value="Server=localhost;UID=sa;PWD=secret;Database =myDB" /> [/ref]
    PW`? 
    >
    >
    >.
    >[/ref]


    Teemu Guest

  3. #3

    Default Re: <appsettings>

    "Kenneth" <se> wrote in message
    news:08f501c366e9$16a21540$gbl... 

    Kenneth,

    You can do the following in web.config:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <appSettings file="user.config">
    <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
    com


    John Guest

Similar Threads

  1. Web.Config and appSettings tag
    By Stevet96 in forum ASP.NET Web Services
    Replies: 1
    Last Post: January 7th, 07:39 PM
  2. How secure are appsettings in web.config?
    By Tim Wood in forum ASP.NET Security
    Replies: 1
    Last Post: November 25th, 03:54 PM
  3. How: Ampersand in AppSettings value??
    By Eidolon in forum ASP.NET Security
    Replies: 2
    Last Post: September 9th, 04:58 PM
  4. appSettings problem!
    By Manuel Adam in forum ASP.NET General
    Replies: 1
    Last Post: August 5th, 06:58 AM
  5. ConfigurationSettings.AppSettings Error
    By Bassel Tabbara [MSFT] in forum ASP.NET General
    Replies: 1
    Last Post: July 7th, 08:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139