Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
2 like 0 dislike
in .Net Framework by 36 42 54
edited by
I am working on an MVC solutions and I retrieve configuration values from Web.Config in an MVC , How can I do that in MVC?

1 Answer

2 like 0 dislike
by 36 42 54
Best answer

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

        <add key="NewSetting" value="NewValue" />
  • 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"];
If you don’t ask, the answer is always NO!