对.NET Core中的web.config感到困惑 [英] Am confused about web.config in .NET Core

查看:93
本文介绍了对.NET Core中的web.config感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于web.config和.NET Core有很多矛盾的说法.

There are a bunch of contradictory statements about web.config and .NET Core.

  • 地方说它不见了.

    此外,我刚刚将几乎全新的.NET Core应用程序部署到Azure.在存储库中,没有web.config,但是当我在Kudu中浏览已部署的代码时,有一个web.config文件吗?


    .NET Core中的web.config是怎么回事?您应该如何做非定制应用程序配置"的东西?(例如HTTP标头和其他HTTP级别配置)

    Additionally, I've just deployed a mostly-fresh-out-of-the-box .NET Core app to Azure. In the repository, there's no web.config but when I explore the deployed code in Kudu, there IS a web.config file?


    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用于两个目的:

    In a .NET Framework Web application, web.config is used for two purposes:

    1. 存储Web应用程序的配置.

    1. To store configuration for the web application.

    要存储承载应用程序的IIS的配置( system.webServer 元素).

    To store configuration for the IIS that hosts the application (system.webServer element).

    在.NET Core Web应用程序中,您至少有两个选择来存储应用程序配置:

    In a .NET Core Web application, you have at least two choices for storing application configuration:

    • Use a .NET Core Configuration Provider, often with a json configuration file.

    使用 System.Configuration.ConfigurationManager NuGet软件包与.NET Core的最新版本(我认为是2.0+).使用 System.Configuration.ConfigurationManager 的优点之一是可以在与.NET Core和.NET Framework兼容的.NET Standard 2.0库中使用.

    Use the System.Configuration.ConfigurationManager NuGet package with recent versions of .NET Core (2.0+ I think). One advantage of using System.Configuration.ConfigurationManager is that it can be used in .NET Standard 2.0 libraries that are compatible with both .NET Core and .NET Framework.

    如果您选择在.NET Core Web应用程序中使用 System.Configuration.ConfigurationManager ,则需要添加 app.config (不是 web.config )文件添加到您的Visual Studio项目中.构建此项目时,它将被复制到输出目录,并重命名为 appName.dll.config .

    If you choose to use System.Configuration.ConfigurationManager in a .NET Core web application, you need to add an app.config (not web.config) file to your Visual Studio project. When you build this project it will be copied to the output directory and renamed as appName.dll.config.

    如果要在IIS中托管.NET Core Web应用程序,则仍然需要具有IIS配置的 web.config 文件( system.webServer 元素).IE.您的应用程序可能同时需要 app.Config web.config .

    If you are hosting your .NET Core web application in IIS, you can still need a web.config file with configuration for IIS (system.webServer element). I.e. your application may need both app.Config and web.config.

    我个人更喜欢使用 System.Configuration.ConfigurationManager app.config XML配置文件,原因有很多,包括与.NET Framework的兼容性,很容易将XML等位注释掉.当然是YMMV.

    Personally I prefer to use System.Configuration.ConfigurationManager and an app.config XML configuration file, for several reasons including compatibility with .NET Framework, the fact that it's easy to comment out bits of XML, etc. YMMV of course.

    这篇关于对.NET Core中的web.config感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆