Avatar of volking
volking
 asked on

Is a GENERIC web.config possible?

I build ASP.NET websites on my local box, then PUBLISH them to webservers.

I have about a dozen WEB.CONFIG settings, which need to change, every time I publish to a webserver. So, I've been EXCLUDING the WEB.CONFIG from my projects so they don't overlay the differences on each webserver ....

Arrrrrrrgh! Meaning, any time I make a web.config change, I gotta MANUALLY update all the other webserver's web.config files ....

Has anyone successfully built a GENERIC web.config?

Meaning, all web.config settings, for ALL webservers, are in one web.config, and the SERVER decides, based on it's NAME, which section of the Web.Config to use?

Editors IDEs.NET Programming

Avatar of undefined
Last Comment
volking

8/22/2022 - Mon
Bob Learned

What kind of settings are you talking about here?  I am going to assume ASP.NET 2.0.

Bob
donkitchen

I use an alternate solution where I have multi-layered config files.  So, for example, I have my main web.config, which keeps application settings in an external file, externalsettings.config.

I then have a few different externalSettings files with different settings.  Like externalSettings.test, externalSettings.prod.  You can then via various methods (post build steps, batch files, etc) rename the target file to the proper externalSettings.config based on which environment (or server) you are deploying to.
<appSettings file="externalSettings.config"/>

Open in new window

Aaron Jabamani

You can also set the settings in the Machine.Config, so that all are applied to all the sites in the server. No need to change in the web.config.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
volking

ASKER
@TheLearnedOne - like these kind of settings  

<connectionStrings>
    <add name="LocalSqlServer" connectionString="Server=XXX;Initial Catalog=XXX;User=XXX;password=XXX;" providerName="System.Data.SqlClient"/>
</connectionStrings>
volking

ASKER
@donkitchen - yep, that's exactly what I'm trying to AVOID. I want the CONFIG file (plus maybe the current server name) to auto-magically use a different setting
volking

ASKER
ok ... if I were to imagine HOW it might look ..... what I'm loooking would look SOMETHING LIKE THIS ....
<configuration>
   <connectionStrings>
      <HOSTNAME="XXX">
         <add name="LocalSqlServer" connectionString="Server=AAA;Initial Catalog=MyDB;"/>
      </HOSTNAME="XXX">
      <HOSTNAME="YYY">
         <add name="LocalSqlServer" connectionString="Server=BBB;Initial Catalog=MyDB;"/>
      </HOSTNAME="YYY">
      <HOSTNAME="ZZZ">
         <add name="LocalSqlServer" connectionString="Server=DDD;Initial Catalog=MyDB;"/>
      </HOSTNAME="ZZZ">
   </connectionStrings>
</configuration>

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Bob Learned

You can have multiple connection strings in a single connection string, and pull the correct one based on something like host name using ConfigurationManager.ConnectionStrings.

Bob
volking

ASKER
@TheLearnedOne

Sure, using code, one can do anything. But what about inter-dependent settings. The below membership, profile and roleManager settings all rely on a NAMED CONNECTIONS string. One cannot rely on code to use the correct ConnestString ...

Thus this question about truely generic .CONFIG files.
  <connectionStrings>
    <clear/>
    <add name="SqlServices" connectionString="Server=XXX;Initial Catalog=XXX;User=XXX;password=XXX;"
        ProviderName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <membership 
      defaultProvider="SqlProvider" 
        userIsOnlineTimeWindow="20" 
        hashAlgorithmType="SHA1">
      <providers>
        <clear/>
        <add name="SqlProvider"
          type="System.Web.Security.SqlMembershipProvider"
          connectionStringName="SqlServices"
          enablePasswordRetrieval="false"
          enablePasswordReset="true"
          requiresQuestionAndAnswer="true"
          passwordFormat="Hashed"
          applicationName="/"
          requiresUniqueEmail="true"
          maxInvalidPasswordAttempts="5"
          minRequiredPasswordLength="4"
          minRequiredNonalphanumericCharacters="0"
          passwordAttemptWindow="10"
          passwordStrengthRegularExpression="" />
      </providers>
    </membership>
    <profile defaultProvider="SqlProvider">
      <providers>
        <clear />
        <add name="SqlProvider"
          type="System.Web.Profile.SqlProfileProvider"
          connectionStringName="SqlServices"
          applicationName="SampleApplication"
          description="SqlProfileProvider for SampleApplication" />
      </providers>
    </profile>
    <roleManager cacheRolesInCookie="true" cookieName=".ASPROLES"
      cookieRequireSSL="true" defaultProvider="SqlProvider">
      <providers>
        <clear />
        <add connectionStringName="SqlServices" applicationName="asbusa"
          name="SqlProvider" type="System.Web.Security.SqlRoleProvider" />
      </providers>
    </roleManager>    
  </system.web>

Open in new window

volking

ASKER
@TheLearnedOne - in the above sample, notice lines 15 & 34 reference a named connectstring called "SqlProvider" which is defined in line 3. The "trick" is using a different Line 3 based on hostname (or some such host-relative value).

That's what I'm looking for. A way to dynamicly change line 3 based on SOMETHING? And thus, changing line 3, causes functional cascades through the entire .CONFIG file.

Fred
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Bob Learned

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
volking

ASKER
@TheLearnedOne

Smile ... thank you ... sometimes the right answer is "No" .... I didn't think it was possible, but thought asking others, "wouldn't hurt" ...