Read web.config keys in MVC
To Retrieve Configuration Values from Web.Config in MVC, you should follow the below steps in detail:
1- Open your MVC application and find Web.Config in the root directory of your project.
2- Add a new Key with its value in appSettings section
<configuration>
<appSettings>
<add key="NewSetting" value="NewValue" />
</appSettings>
</configuration>
- NewSetting : That's the key that is used in the code to retrieve its corresponding value for example : replace NewSetting with RootURL
- NewValue : That's the value for example : replace NewValue with https://www.google.com/
3- In the controller, you need to write the following code to retrieve data using the RootURL from the configuration.
string RootURL= System.Configuration.ConfigurationManager.AppSettings["RootURL"];