简体   繁体   中英

Can't read from appSettings

I have a test project with a web.config file in the test project. I keep getting null when I try to read a value from the appSettings section of the web.config.

I have a reference to System.configuration and a using statement using System.Configuration;

    <appSettings>
<add key="SatisfactionSurveyLink" value="Link"/>
    </appSettings>


        [TestMethod()]
        public void TestReadFromAppSettings() 
        {
            String surveyLink = ConfigurationManager.AppSettings["SatisfactionSurveyLink"];

            Assert.IsNotNull(surveyLink);
        }

I've tried many different things and can't get this to work. Does anyone have any suggestions as to what the problem could be?

thanks,

Ronald

如果它是作为类库创建的测试项目,则不需要web.config而是app.config ;-)

Does anyone have any suggestions as to what the problem could be

Have you double-checked you've not mistyped the key, either in the web.config itelf, or when you read it out?

Is it possible something is updating the value before you read it?

Is the build action of the web.config set as "Content" in the properties window?

你说你有一个测试项目,你应该有一个app.config

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM