Different configuration files on local vs. server.

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

    Different configuration files on local vs. server.

    How can you have different web.config files on your test machine vs.
    production? I realize I could not include it in the project but the problem
    is that if I make changes that go in both places I need to have them in both
    places. But things like connect strings need to be different.

    Can I have two config files and only include one of them in the project so
    it get's published but the other one doesn't?

    TIA - Jeff.


  • sloan

    #2
    Re: Different configuration files on local vs. server.

    One Idea:

    Push certain things out to external files:



    <?xml version="1.0" encoding="utf-8" ?>
    <configuratio n>


    <appSettings file="CustomApp Settings.config " >
    </appSettings>


    <connectionStri ngs configSource="E xternalConnecti onStrings.confi g" />


    </configuration>

    ............... .....

    AppSettings.con fig

    <appSettings>


    <add key="Key1" value="Value1"/>

    </appSettings>


    .............

    ExternalConnect ionStrings.conf ig
    <connectionStri ngs >


    <add name="MyDatabas eInstance" connectionStrin g="server=.;dat abase=MYDB;User
    ID=user1;passwo rd=password1" providerName="S ystem.Data.SqlC lient"/>

    </connectionStrin gs>





    Note, you'll have to use the POST BUILD EVENTS to get the files to copy in
    (non web) projects.


    Just right click / Add new item / app config (and then rename )





    "Mufasa" <jb@nowhere.com wrote in message
    news:%23gkpTsmG JHA.4600@TK2MSF TNGP06.phx.gbl. ..
    How can you have different web.config files on your test machine vs.
    production? I realize I could not include it in the project but the
    problem is that if I make changes that go in both places I need to have
    them in both places. But things like connect strings need to be different.
    >
    Can I have two config files and only include one of them in the project so
    it get's published but the other one doesn't?
    >
    TIA - Jeff.
    >
    >

    Comment

    • Mark Rae [MVP]

      #3
      Re: Different configuration files on local vs. server.

      "sloan" <sloan@ipass.ne twrote in message
      news:elB7l0mGJH A.3932@TK2MSFTN GP03.phx.gbl...

      [top-posting corrected]
      >How can you have different web.config files on your test machine vs.
      >production?
      >
      One Idea:
      <snip>

      No need to go through all that - just install Web Deployment Projects:



      --
      Mark Rae
      ASP.NET MVP


      Comment

      • Mufasa

        #4
        Re: Different configuration files on local vs. server.

        So if I have two config files and include them both in the project it will
        find them both?

        What happens if the same things are in both files?

        TIA.

        "sloan" <sloan@ipass.ne twrote in message
        news:elB7l0mGJH A.3932@TK2MSFTN GP03.phx.gbl...
        One Idea:
        >
        Push certain things out to external files:
        >
        >
        >
        <?xml version="1.0" encoding="utf-8" ?>
        <configuratio n>
        >
        >
        <appSettings file="CustomApp Settings.config " >
        </appSettings>
        >
        >
        <connectionStri ngs configSource="E xternalConnecti onStrings.confi g" />
        >
        >
        </configuration>
        >
        ............... ....
        >
        AppSettings.con fig
        >
        <appSettings>
        >
        >
        <add key="Key1" value="Value1"/>
        >
        </appSettings>
        >
        >
        ............
        >
        ExternalConnect ionStrings.conf ig
        <connectionStri ngs >
        >
        >
        <add name="MyDatabas eInstance"
        connectionStrin g="server=.;dat abase=MYDB;User ID=user1;passwo rd=password1"
        providerName="S ystem.Data.SqlC lient"/>
        >
        </connectionStrin gs>
        >
        >
        >
        >
        >
        Note, you'll have to use the POST BUILD EVENTS to get the files to copy in
        (non web) projects.
        >
        >
        Just right click / Add new item / app config (and then rename )
        >
        >
        >
        >
        >
        "Mufasa" <jb@nowhere.com wrote in message
        news:%23gkpTsmG JHA.4600@TK2MSF TNGP06.phx.gbl. ..
        >How can you have different web.config files on your test machine vs.
        >production? I realize I could not include it in the project but the
        >problem is that if I make changes that go in both places I need to have
        >them in both places. But things like connect strings need to be
        >different.
        >>
        >Can I have two config files and only include one of them in the project
        >so it get's published but the other one doesn't?
        >>
        >TIA - Jeff.
        >>
        >>
        >
        >

        Comment

        • Mark Rae [MVP]

          #5
          Re: Different configuration files on local vs. server.

          "Mufasa" <jb@nowhere.com wrote in message
          news:O4c7nMnGJH A.3936@TK2MSFTN GP03.phx.gbl...

          [top-posting corrected]
          >One Idea:
          <snip>
          So if I have two config files and include them both in the project it will
          find them both?
          >
          What happens if the same things are in both files?
          With Web Deployment Projects, none of the above matters...


          --
          Mark Rae
          ASP.NET MVP


          Comment

          • Tiberiu Covaci

            #6
            Re: Different configuration files on local vs. server.

            Hi Mufasa,

            There is a third option. Web.config might be found at different levels:
            - Machine (C:\Windows\Mic orsoft.Net\Fram ework\v???\conf ig\web.config)
            - Web site (Root_folder_of _your_web_site\ Web.config)
            - Your web application (web.config)
            - Your subfolder in your application(ano ther web.config)
            If you want something to be available machine wide, you can just put it on
            you machine web.conf, and then it wil propagate to your application. If you
            want to change that value at a different level, just change it in that
            place.

            Regards,
            Tibi
            MCT

            "Mufasa" <jb@nowhere.com wrote in message
            news:%23gkpTsmG JHA.4600@TK2MSF TNGP06.phx.gbl. ..
            How can you have different web.config files on your test machine vs.
            production? I realize I could not include it in the project but the
            problem is that if I make changes that go in both places I need to have
            them in both places. But things like connect strings need to be different.
            >
            Can I have two config files and only include one of them in the project so
            it get's published but the other one doesn't?
            >
            TIA - Jeff.
            >
            >

            Comment

            Working...