I keep reading that the new MVC avoids using System.Web by default as that used to add lots of extra stuff automatically.
Does that mean that in order to read the config file now in MVC5, one should use from System.Net instead?
Thanks...
In order to set up the ASP.NET Core Module correctly, the web. config file must be present at the content root path (typically the app base path) of the deployed app.
Setup configurationASP.NET Core no longer uses the Global. asax and web. config files that previous versions of ASP.NET utilized.
The key/value pairs specified in the <appSettings> element are accessed in code using the ConfigurationSettings class. You can use the file attribute in the <appSettings> element of the Web. config and application configuration files.
Click Add to create the file and open it for editing. The file contains the code shown in the "Example" section later in this topic, with a few initial defaults. Your application inherits all configuration settings from the Machine. config and Web.
It should be:
string key = System.Configuration.ConfigurationManager.AppSettings.Get("AppKey");
OR
string key = System.Configuration.ConfigurationManager.AppSettings["AppKey"];
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