I am not sure how to use my application settings in my mvc4 application. For example I have an setting (stored in db), wether to use logging or not.
Should I load the setting once at application startup and then store it in the session-variable and check it against that? Or should I everytime i invoke an actionresult load the setting from database?
Whats the best practise here?
You can keep this setting in web.config file:
<appSettings>
<add key="enableLogging" value="false"/>
</appSettings>
And access it like this (requires reference to System.Configuration assembly):
ConfigurationManager.AppSettings["enableLogging"];
Note that this stores only string values, so you could parse it or just compare against string.
in this case store it in :
HttpContext.Current.Cache
storing it there will be available to all the requests and set the expire to 24 hours for example
this is not permanent storage , so whenever it expire you need to read it from DB
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