© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
11 replies
Kiel

❔ Environment variables vs configuration files for storing secrets

A project I am working on started out with very few, very simple (string) secrets and sensitive information - so I stored them as environment variables and accessed them via
IConfiguration
IConfiguration
and
config.AddEnvironmentVariables("FOO_");
config.AddEnvironmentVariables("FOO_");
in my host builder. However, as the project has grown in size, the number and type of secrets has grown too, and some of them are too complex to store as the simple Key:Value format environment variables entail. At the moment, I have my original simple string secrets still stored as environment variables, but my more complex configuration and secret data has been tossed into a
config.json
config.json
file which I load and add to my IConfiguration via
config.AddJsonFile("config.json");
config.AddJsonFile("config.json");
.

Is it dumb to use both like this, or should I just move my string secrets to this
config.json
config.json
file as well? I'm not concerned about leaking secrets in commits or anything, as I have already added this file to my
.gitignore
.gitignore
for the project, but I'm not extremely keen on best-practices for secrets when it comes to projects. I feel like doing both doesn't really make sense, since the point of the former (to me) was to avoid the latter, but now I have to do the latter, so I might as well put all my eggs in one basket.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Storing Secrets
C#CC# / help
6mo ago
need some help understanding configuration comming from "Environment Variables"
C#CC# / help
3y ago
✅ How to read Environment Variables in VS Code ?
C#CC# / help
17mo ago
Get Environment Variables...
C#CC# / help
4y ago