开发者

Can't read from appSettings

开发者 https://www.devze.com 2023-03-25 23:23 出处:网络
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 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.configurat开发者_运维问答ion 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


if it is a test project created as class library, does not need the web.config but the 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?


You said you have a test project, you should have an app.config then

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号