关于 web.config 和 .NET Core 有很多相互矛盾的说法。
- Places saying it's gone.
- https://dotnetcore.show/episode-10-configuration-in-net-core/ https://dotnetcore.show/episode-10-configuration-in-net-core/
- Places saying it was gone but now it's back.
- https://stackoverflow.com/a/46771737/1662268 https://stackoverflow.com/a/46771737/1662268
- Places saying that it's no longer necessary, but you can create one manually:
- https://stackoverflow.com/a/43890405/1662268 https://stackoverflow.com/a/43890405/1662268
- https://stackoverflow.com/a/53731666/1662268 https://stackoverflow.com/a/53731666/1662268
此外,我刚刚将一个几乎全新的开箱即用的 .NET Core 应用程序部署到 Azure。
在存储库中,没有 web.config,但是当我探索 Kudu 中的部署代码时,有一个 web.config 文件吗?
What's going on with web.config in .NET Core?
How are you supposed to do non-Custom-App-Configuration stuff? (e.g. HTTP headers and other HTTP level config)
在 .NET Framework Web 应用程序中,web.config 有两个用途:
存储 Web 应用程序的配置。
存储托管应用程序的 IIS 的配置 (system.webServer
元素)。
在 .NET Core Web 应用程序中,您至少有两种存储应用程序配置的选择:
Use a .NET Core 配置提供程序 https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.2,通常带有 json 配置文件。
Use the 系统.配置.配置管理器 https://www.nuget.org/packages/System.Configuration.ConfigurationManager/NuGet 包包含最新版本的 .NET Core(我认为是 2.0+)。使用的好处之一System.Configuration.ConfigurationManager
的优点是它可以在与 .NET Core 和 .NET Framework 兼容的 .NET Standard 2.0 库中使用。
如果您选择使用System.Configuration.ConfigurationManager
在 .NET Core Web 应用程序中,您需要添加app.config
(not web.config
) 文件添加到您的 Visual Studio 项目。当您构建此项目时,它将被复制到输出目录并重命名为appName.dll.config
.
如果您在 IIS 中托管 .NET Core Web 应用程序,您仍然需要web.config
包含 IIS 配置的文件(system.webServer
元素)。 IE。您的应用程序可能需要两者app.Config
and web.config
.
我个人更喜欢使用System.Configuration.ConfigurationManager
and an app.config
XML 配置文件,出于多种原因,包括与 .NET Framework 的兼容性、可以轻松注释掉 XML 部分等事实。当然,YMMV。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)