【问题标题】:Add app.config to .net core 3.1 web api application将 app.config 添加到 .net core 3.1 web api 应用程序
【发布时间】:2020-05-14 14:42:31
【问题描述】:

我正在将我的项目从 .net 框架转移到 .Net core 3.1 web api。 .Net 似乎不包含 app.config 文件,我需要添加它。我添加了一个,但它无法识别。有没有办法将 app.config 文件添加到 .Net 核心应用程序?还是 app.config .net core 的替代品?

App.config:

<configSections>
        <section name="corememorycache" type="NHibernate.Caches.CoreMemoryCache.CoreMemoryCacheSectionHandler,NHibernate.Caches.CoreMemoryCache" />
        <section name="hibernate-configuration"
                 type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
    </configSections>

    <corememorycache expiration-scan-frequency="00:05:00">
        <cache region="foo" expiration="500" sliding="true" />
        <cache region="noExplicitExpiration" sliding="true" />
    </corememorycache>

【问题讨论】:

  • 嗨,约翰尼,欢迎来到社区!您是否已经阅读了documentation here 中的步骤大纲并且您还没有找到解决方案?通常 .Net 核心配置发生在 Startup.cs 文件中,并且可以在 AppSettings.json 文件中添加其他配置。如果您还没有,请创建一个新的 .NET 核心应用程序并查看结构和包含的文件以获取提示,并报告回来。如果您发现自己的问题受到鼓励,请发布答案。

标签: asp.net-core asp.net-core-webapi app-config asp.net-core-3.1


【解决方案1】:

在 .NET Core 中,方法有点不同。默认情况下你应该使用appsettings.jsonfile

这是一篇关于 .NET Core 配置的文章: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 2021-04-11
    • 2020-04-27
    • 2020-09-15
    • 1970-01-01
    • 2021-03-06
    相关资源
    最近更新 更多