【发布时间】:2021-03-01 16:19:35
【问题描述】:
我需要从我的 cshtml 文件中访问 web.config appSettings 中的值
这是我在 cshtml 文件中的代码:
<body>
<div>
@RenderBody()
<footer>
<p @System.Configuration.ConfigurationManager.AppSettings["myKey"]</p>
</footer>
</div>
...
</body>
这是我来自 web.config 的代码
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="myKey" value="MyValue"/>
</appSettings>
</configuration>
提前致谢
【问题讨论】:
-
那么这段代码有什么问题。我在这里看到的唯一错误是您没有正确关闭起始
标记。
-
我实际上可以从 app.config 访问值,但不能从 web.config 访问。你知道什么可能导致从 web.config 访问它的问题吗?
-
您使用的是 .NET 核心吗?
-
没错,我用的是.Net core
标签: asp.net-core .net-core configuration web-config settings