Keith Hill
Keith Hill

Reputation: 202032

How is config.json found by ASP.NET 5

Presumably everything an ASP.NET 5 web site needs to run gets put under wwwroot. Yet when I look at this dir when the site is running I don't see config.json. So the question is, how does my web site startup code find config.json if it isn't under wwwroot?

A related question, if I want to create my own config file (since config.json only handles simple name/value pairs), would I put it next to config.json in my project or under wwwroot in order to be able to read the contents at runtime?

Upvotes: 3

Views: 1171

Answers (1)

proggrock
proggrock

Reputation: 3289

What's in the wwwroot folder represents everything accessible to your site from HTTP. You can access your config files at runtime, but you can't make web requests for them (since they're not in wwwroot).

ASP.NET finds the root config.json in the Startup class:

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

Upvotes: 3

Related Questions