Oren Baldinger Oren Baldinger - 5 months ago 15
Ini Question

Environment variables file in C#?

I'm new to C#, coming from a PHP background I'm accustomed to storing things like database/smtp config in an environment file excluded from source control, so that the application can run locally and in multiple environments. Is there an equivalent convention in C#/ASP.NET? Maybe an .ini file somewhere? Web.config is a possible candidate, but there is dependency information in there as well (like a composer.json), so maybe not.


web.config is correct. You can add custom key/value pairs using the appSettings tag:

    <add key="CustomKey" value="Custom Value" />

and then accessing it through:


ASP.NET Web Configuration Guidelines ConfigurationManager.AppSettings Property