James Woodall
James Woodall

Reputation: 735

ContentRootPath different in Development and Azure web app

When I deploy my Dot Net Core web app to Azure, the Environment.ContentRootPath variable is set to [myproject]/wwwroot. However, in development, it is just [myproject].

Why does it change in Azure deployment?

How can I make it consistent?

For reference, this is my IWebHost.

public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((builderContext, config) =>
                {
                    var env = builderContext.HostingEnvironment;

                    config.AddJsonFile("appsettings.json", false, true)
                        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, true);

                    if (env.IsDevelopment())
                        config.AddUserSecrets<Startup>();

                    config.AddEnvironmentVariables();
                })
                .UseSetting("detailedErrors", "true")
                .UseApplicationInsights()
                .UseStartup<Startup>()
                .CaptureStartupErrors(true)
                .Build();

Upvotes: 5

Views: 3646

Answers (1)

Bruce Chen
Bruce Chen

Reputation: 18465

Use KUDU, you could find that your web contents are deployed to D:\home\site\wwwroot as follows:

enter image description here

By default, D:\home\site\wwwroot would be used as the content root and the host would search the content files (e.g. MVC view files,etc.) when hosting your application on Azure Web App.

In development, your app is started from the project's root folder, so the project's root folder is used as the content root.

Per my understanding, you may misunderstand the wwwroot folder in your project with the wwwroot folder on Azure Web App for storing your web content.

Moreover, you could use UseContentRoot to customize your content root folder. If the path doesn't exist, the host would fail to start. Details you could follow Hosting in ASP.NET Core.

Upvotes: 5

Related Questions