web.config的连接字符串未通过configurationManager.connectionstrings读取[test; test']。connectionsTring
我的web.config文件中有一个连接字符串:
<configuration>
<connectionStrings>
<add name="Test" connectionString="MyConnString"/>
</connectionStrings>
</configuration>
并且正在尝试在我的代码中访问它:
string connectionString = ConfigurationManager.ConnectionStrings["Test"].ConnectionString;
为什么我会收到此错误?
nullReferenceException:对象引用未设置为一个实例 对象。
configurationManager.connectionstrings [“ test”]
是无效的,但我不知道原因。
I am using ASP.NET Core 3.1
I installed System.Configuration.Configuration
version 6.0.0 using NuGet.
我使用代码文件顶部的语句具有正确的正确信息:使用System.Configuration;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
阅读以下文章:迁移配置为asp。 NET Core
So, you can rename the
web.config
toapp.config
.但是更好的解决方案是更新应用程序以使用JSON-Formatted文件,例如
AppSettings.json
。有关更多信息,请阅读以下文章:中Read the following article: Migrate configuration to ASP.NET Core
So, you can rename the
web.config
toapp.config
.But better solution is to update application to use JSON-formatted file, such as
appsettings.json
. For more information read the following article: Configuration in ASP.NET Core