vb.net 使用 appsettings,但“ConfigurationSettings”方法已过时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6383966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:33:16  来源:igfitidea点击:

Using appsettings, but "ConfigurationSettings" method is obsolete

vb.netappsettingswindows-applications

提问by Urbycoz

I've trying to access an appsettings key value in my vb.net 2.0 web application.

我试图访问我的 vb.net 2.0 Web 应用程序中的 appsettings 键值。

I've put the key in the app.config file:

我已将密钥放在 app.config 文件中:

<appSettings>
    <add key="DownloadURL" value="http://<myURL>/" />
</appSettings>

I've followed the instructions here, and it says that I need to access this key like so:

我已按照此处的说明进行操作,它说我需要像这样访问此密钥:

URL = System.Configuration.ConfigurationSettings.AppSettings("DownloadURL")

But I get the following message:

但我收到以下消息:

Public Shared Readonly property AppSettings() As 'System.Collections.Specialized.NameValueCollection' is obsolete: 'This method is obsolete, it has been replaced by System.configuration!System.configuration.configurationmanager.AppSettings'

公共共享只读属性 AppSettings() 由于 'System.Collections.Specialized.NameValueCollection' 已过时:'此方法已过时,已被 System.configuration!System.configuration.configurationmanager.AppSettings 取代'

I tried to replace the old method with the new one, but it does not exist.

我试图用新方法替换旧方法,但它不存在。

Strange, since I've done a similar thing with a web app and it did exist there.

奇怪,因为我用一个网络应用程序做了类似的事情并且它确实存在于那里。

回答by Gerrie Schenck

Add a reference to System.Configuration.dll.

添加对 System.Configuration.dll 的引用。

Here's an explanation.

这是一个解释。