大概 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/