Oren Baldinger Oren Baldinger - 4 years ago 283
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download