I have an C# MVC 5 app, which I intent to run in two places: a)Internet facing b) corporate Intranet I need to have my application code be aware of the environment (External Vs. Internal) in which it runs, so I can hide some features and options, which are not appropriate for the External instance. So, I'm thinking along the lines of creating some sort of distinct variable within my Web.config, to which I could assign either "external" or "internal" value.
My question is: what is the proper place and proper syntax to declare such variable, and where/how in my application C# code can I read that value, which should be read early enough in the app life cycle to give my JavaScript code (which is loaded in _layout.cshtml) a chance to act according to the "external"/"internal" value.
You should put your value in appSettings, like:
<configuration>
<appSettings>
<add key="Environment" value="External" />
</appSettings>
</configuration>
And you can pull it out like:
System.Configuration.ConfigurationManager.AppSettings["Environment"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With