从App.config中配置没有被正确被拉 [英] Configuration from App.config isn't being pulled correctly

查看:121
本文介绍了从App.config中配置没有被正确被拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图提取我保存到app.config文件的URL,但它返回一个空字符串。任何想法,为什么?



 字符串ASDF =的String.Format({0},ConfigurationManager.AppSettings [的memberURL]) ; 

和配置文件:

 <?XML版本=1.0编码=UTF-8>?; 
<结构>
<&的appSettings GT;
<添加键=ForumUrlVALUE =htt​​p://www.dreamincode.net/forums/xml.php?showforum=/>
<添加键=的memberURLVALUE =htt​​p://www.dreamincode.net/forums/xml.php?showuser=/>
< /的appSettings>
< /结构>


解决方案

所有的配置信息,您的类库的需求必须是主体工程的App.config或web.config中。换句话说,如果你的app.config文件附加到库也不会被读取。



进入主应用程序,并添加适当的键/值,它是配置文件。


I'm trying to extract a URL I saved to the app.config file, but it's returning a blank string. Any ideas why?

string asdf = String.Format("{0}", ConfigurationManager.AppSettings["MemberUrl"]);

And the configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="ForumUrl" value="http://www.dreamincode.net/forums/xml.php?showforum=" />
    <add key="MemberUrl" value="http://www.dreamincode.net/forums/xml.php?showuser=" />
  </appSettings>
</configuration>

解决方案

All config information that your class library needs must be in the main projects App.config or web.config. In other words, if your app.config file is attached to the library it will NOT be read.

Go to the main application and add the appropriate keys/values to it's config file.

这篇关于从App.config中配置没有被正确被拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆