我如何从app.config文件中读取

编程入门 行业动态 更新时间:2024-10-27 08:24:40
本文介绍了我如何从app.config文件中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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文件中读取

本文发布于:2023-11-04 17:30:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1558564.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   app   config

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!