Last post Aug 26, 2016 10:27 AM by Yohann Lu
Aug 25, 2016 08:21 PM|NJ2|LINK
I am reviewing someone else's old code which references an appseeting value as :
But, when I open up web.config, I do not see any thing in AppSettings. The code compiles with no error and the only tag I see in web.config is <appSettings/>
Aug 25, 2016 09:36 PM|Janshair Khan|LINK
The web.config file changes from project to project. Someone else's code that you are seeing might have used WebConfigurationManager.AppSettings["MyAppFolder"] for setting some static string value such as title or get a reference from.
If you scaffold a context class using VS, Entity Framework will put some connection string data into your web.config file and something like that. Add the following code into your web.config to see if the above fulfills your requirement or not?
<!-- some stuff omitted here -->
<add key="MyAppFolder" value="New York Times"/>
Note: It would be much better if you explain your code and the problem that you are confronting so that we can help you better understand and help you to solve the issue.
Aug 25, 2016 09:53 PM|PatriceSc|LINK
It won't cause a compile error but what if you try to put a breakpoint and see which value is returned? You may have to add an entry to configure this value to point to some folder depending on what the app does with this folder.
Sometimes the code also includes a default value if no value is found in the config file.
Aug 26, 2016 10:27 AM|Yohann Lu|LINK
Other community members give you some explanation about WebConfigurationManager.AppSettings["MyAppFolder"]. I will do supplement, I hope you can better understand.
I have provided an official document and an example. You can refer them.
ASP.NET appSettings Example:
when I open up web.config, I do not see any thing in AppSettings
You should add the MyAppFolder markup to the Web.config file. First, open your Web.config file in the Solution Explorer. Find the <configuration> container tag, and add an <appSettings> section. Otherwise, the program will get an error when read the value.