ContentRootPath在开发和Azure Web应用程序中有所不同 [英] ContentRootPath different in Development and Azure web app

查看:150
本文介绍了ContentRootPath在开发和Azure Web应用程序中有所不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将Dot Net Core Web应用程序部署到Azure时, Environment.ContentRootPath 变量设置为 [myproject] / wwwroot 。但是,在开发中,它只是 [myproject]



为什么在Azure部署中会发生变化? p>

如何使其保持一致?



作为参考,这是我的 IWebHost

 公共静态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();


解决方案

使用



默认情况下, D:\home\site\wwwroot 用作内容根,当将应用程序托管在Azure Web App上时,主机将搜索内容文件(例如MVC视图文件等)。



在开发中,您的应用是从项目的根文件夹启动的,因此项目的根文件夹用作内容根。



根据我的理解,您可能会误解项目中的 wwwroot 文件夹和Azure上的 wwwroot 文件夹



此外,您可以使用 UseContentRoot 自定义内容根文件夹。如果该路径不存在,则主机将无法启动。您可以遵循的详细信息在ASP.NET Core中进行托管


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();

解决方案

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

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.

这篇关于ContentRootPath在开发和Azure Web应用程序中有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆