Storing web.configs in source control safely (2024)

Christopher Jennings

While it is necessary when using source control to store the web.config files in the repository, it is best practice to separate out any sensitive or environment specific values to separate files and exclude those files from source control. This article explores some best practices on how to do that.

Some examples of the kinds of sensitive or environment specific values you want to exclude are:

  • CMS hash string salt
  • cloud service usernames/passwords
  • connection strings
  • etc.

For the purposes of this article, we'll discuss the two main web.config sections that include sensitive or environment-specific data in a typical Kentico instance, the appSettings and connectionStrings sections. To prepare the appSettings section to have sensitive data removed, locate the appSettings section opening tag and change it to the following:

<appSettings file="AppSettings.config">

All you're doing is adding the file attribute. Leave the settings keys intact, including the sensitive ones, we'll come back to those. Next, create a new file titled "AppSettings.Template.Config" and paste in the following:

<appSettings> <add key="CMSHashStringSalt" value="" /></appSettings>

Add any additional sensitive keys that apply to your project (e.g. CMSAzureAccountName and CMSAzureSharedKey for Azure storage) making sure to leave the actual values blank. Then copy/paste the template file you just created and rename it "AppSettings.config". Edit that file to include the actual values for the sensitive keys in the original web.config and remove the key entirely from the web.config. In the end, your web.config appSettings section will look something like this:

<appSettings file="AppSettings.config"> <add key="CMSProgrammingLanguage" value="C#" /> <add key="WS.webservice" value="http://localhost/WebService/webservice.asmx" /> <add key="CMSTrialKey" value="CX09-20151217-Arnrjm" /> <add key="ChartImageHandler" value="storage=session;timeout=20;" /> <add key="PageInspector:ServerCodeMappingSupport" value="Disabled" /> <add key="CMSApplicationGuid" value="7ff3d58c-f4ef-4441-a45c-3fc21e95eed7" /> <add key="CMSApplicationName" value="Localhost/Kentico" /></appSettings>

Notice that the sensitive key CMSHashStringSalt is not present, but the other non-sensitive ones are. The file attribute on the appSettings key points to a file that will be merged with the appSettings section in the web.config and changes to the external file will not trigger an app restart. The file attribute is specific to the appSettings section. To accomplish the same thing for most other sections, such as the connectionStrings section, we need to use the configSourceattribute. Unlike the fileattribute for the appSettings section, the file that the configSourceattribute points to will replace, not merge with, the web.config, and changes to the external file can trigger an application restart. Let's apply this to the connectionStrings section. First, we'll create a "ConnectionStrings.Template.config" file with the following text:

<connectionStrings> <add name="CMSConnectionString" connectionString="" /></connectionStrings>

If your project has additional connection strings, add them here the same way. Next, copy this template and rename it to "ConnectionStrings.config". In this file update the connectionString values from your web.config. Finally, open the web.config and replace the entire connectionStrings section with the following:

<connectionStrings configSource="ConnectionStrings.config" />

Now your web.config file is safe to check in to source control. Just don't forget to exclude the "AppSettings.config" and "ConnectionStrings.config" files from yoursourcecontrol. You can see an example of this in our MVC sample site repository on GitHub.

Storing web.configs in source control safely (2024)
Top Articles
Top 7 Most Expensive Logos Ever Created » Pixellion's Blog
Big 4 Interview Attire
Duralast Gold Cv Axle
Bashas Elearning
Nehemiah 4:1–23
Online Reading Resources for Students & Teachers | Raz-Kids
1970 Chevelle Ss For Sale Craigslist
Cad Calls Meriden Ct
How Much Is 10000 Nickels
Pickswise the Free Sports Handicapping Service 2023
سریال رویای شیرین جوانی قسمت 338
Apply A Mudpack Crossword
Tribune Seymour
Mercy MyPay (Online Pay Stubs) / mercy-mypay-online-pay-stubs.pdf / PDF4PRO
Tcu Jaggaer
4302024447
Valentina Gonzalez Leak
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
Wisconsin Women's Volleyball Team Leaked Pictures
Craighead County Sheriff's Department
R Personalfinance
The Menu Showtimes Near Regal Edwards Ontario Mountain Village
CDL Rostermania 2023-2024 | News, Rumors & Every Confirmed Roster
Uta Kinesiology Advising
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
8005607994
Powerschool Mcvsd
Relaxed Sneak Animations
Copper Pint Chaska
Cal State Fullerton Titan Online
Tamil Movies - Ogomovies
Melissa N. Comics
Opsahl Kostel Funeral Home & Crematory Yankton
2016 Honda Accord Belt Diagram
Ukg Dimensions Urmc
Bella Thorne Bikini Uncensored
Lovein Funeral Obits
Bartow Qpublic
Vons Credit Union Routing Number
Walgreens On Secor And Alexis
Lawrence E. Moon Funeral Home | Flint, Michigan
Hdmovie2 Sbs
Rocket League Tracker: A useful tool for every player
Premiumbukkake Tour
Dlnet Deltanet
How to Find Mugshots: 11 Steps (with Pictures) - wikiHow
Mit diesen geheimen Codes verständigen sich Crew-Mitglieder
Makes A Successful Catch Maybe Crossword Clue
Pilot Travel Center Portersville Photos
Tommy Gold Lpsg
Mkvcinemas Movies Free Download
Latest Posts
Article information

Author: Virgilio Hermann JD

Last Updated:

Views: 5913

Rating: 4 / 5 (61 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Virgilio Hermann JD

Birthday: 1997-12-21

Address: 6946 Schoen Cove, Sipesshire, MO 55944

Phone: +3763365785260

Job: Accounting Engineer

Hobby: Web surfing, Rafting, Dowsing, Stand-up comedy, Ghost hunting, Swimming, Amateur radio

Introduction: My name is Virgilio Hermann JD, I am a fine, gifted, beautiful, encouraging, kind, talented, zealous person who loves writing and wants to share my knowledge and understanding with you.