问题描述
我有一个app.config文件,我有一个网址,其列为
I have a app.config file that I have a url in and its listed as
<appSettings>
<add key="web" value="http://URL HERE"/>
</appSettings>
然后在我有的文件中
ChatMessengerService.Messenger messenger = new ChatMessengerService.Messenger();
messenger.Url = System.Configuration.ConfigurationManager.AppSettings [web];
bool loginSucces = messenger.Login(用户名,sha1HashStr);
然而它不读,但如果我硬编码它会工作得很好
任何帮助都会很好。
then in a file I have
ChatMessengerService.Messenger messenger = new ChatMessengerService.Messenger();
messenger.Url = System.Configuration.ConfigurationManager.AppSettings["web"];
bool loginSucces = messenger.Login(username, sha1HashStr);
however its not reading but if I hardcoded the url it will work just fine
Any help would be nice.
推荐答案
<configuration>
<appSettings>
<add key="web" value="http://URL HERE" />
</appSettings>
</configuration>
然后使用System.Configuration添加以下引用
;
最后在你的代码中你必须这样写,
messenger.Url = ConfigurationManager.AppSettings [web];
Then add the following reference
using System.Configuration;
And finally in your code section you have to write like this,
messenger.Url = ConfigurationManager.AppSettings["web"];
这篇关于我如何从app.config文件中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!