当我将 Dot Net Core Web 应用程序部署到 Azure 时,Environment.ContentRootPath
变量设置为[myproject]/wwwroot
。但在开发过程中,只是[myproject]
.
为什么 Azure 部署会发生变化?
我怎样才能使其一致?
作为参考,这是我的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 https://blogs.msdn.microsoft.com/benjaminperkins/2014/03/24/using-kudu-with-windows-azure-web-sites/,您会发现您的网页内容已部署到D:\home\site\wwwroot
如下:
默认情况下,D:\home\site\wwwroot
将用作内容根,当在 Azure Web App 上托管应用程序时,主机将搜索内容文件(例如 MVC 视图文件等)。
在开发中,您的应用程序是从项目的根文件夹启动的,因此项目的根文件夹用作内容根目录。
根据我的理解,你可能会误解wwwroot
项目中的文件夹wwwroot
Azure Web App 上用于存储 Web 内容的文件夹。
此外,你可以使用UseContentRoot
自定义您的内容根文件夹。如果该路径不存在,主机将无法启动。您可以关注的详细信息托管在 ASP.NET Core 中 https://learn.microsoft.com/en-us/aspnet/core/fundamentals/hosting?tabs=aspnetcore2x.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)