asp.net - ASP.NET 5 如何找到 config.json

标签 asp.net asp.net-mvc asp.net-core

大概 ASP.NET 5 网站需要运行的所有内容都放在 wwwroot 下。然而,当我在网站运行时查看此目录时,我看不到 config.json。所以问题是,如果我的网站启动代码不在 wwwroot 下,如何找到 config.json?

一个相关的问题,如果我想创建我自己的配置文件(因为 config.json 只处理简单的名称/值对),我会把它放在我项目中的 config.json 旁边还是放在 wwwroot 下以便能够在运行时读取内容?

最佳答案

wwwroot 文件夹中的内容代表您的网站可通过 HTTP 访问的所有内容。您可以在运行时访问您的配置文件,但不能对它们发出 Web 请求(因为它们不在 wwwroot 中)。

ASP.NET 在 Startup 类中找到根 config.json:

public Startup(IHostingEnvironment env)
    {
        // Setup configuration sources.
        var configuration = new Configuration()
            .AddJsonFile("config.json")
            .AddJsonFile($"config.{env.EnvironmentName}.json", optional:   true);

关于asp.net - ASP.NET 5 如何找到 config.json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30513350/

相关文章:

asp.net-mvc - 阻止未确认电子邮件的用户登录 ASP.NET MVC Web API Identity(OWIN 安全)

c# - 用于 3 个表连接的 Entity Framework 7 Lambda 表达式

jquery - 制作第一行的固定标题

asp.net - 通过 TSQL 填充 aspnet_Profile 表

c# - 在 foreach 循环中创建多个 DropDownListFor

database - 使用迁移重命名列时出现 EF Core 2.0 错误

c# - ASP.NET Core 3.1 Web API : can it be self-hosted as Windows service with https and use some certificate like IIS?

c# - 为什么 MVC 5 不调用我的 VirtualPathProvider 类的 GetFile 方法?

c# - 从字符串中获取 HTML 标签

asp.net-core - 如何接受 ASP.NET Core Web API 上的所有内容类型?