我有一个app.config文件,我有一个网址,其列为
I have a app.config file that I have a url in and its listed as
<appSettings> <add key="web" value="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.
推荐答案试试在这样的配置部分编写你的appsettings Trye to write your appsettings in configuration secton like this <configuration> <appSettings> <add key="web" value="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"];
如果你使用的是MVC,那么有2个网页.config文件可用。一个用于视图,另一个用于整个解决方案。请检查您添加了应用密钥的web.config。它应该是解决方案的web.config来获取值。 If you are using MVC, there are 2 web.config file available in it. One for Views and another for the whole solution. Kindly check in which web.config, you have added the app key. It should be solution's web.config for getting the value.
更多推荐
我如何从app.config文件中读取
发布评论