[英]How do we set ContentRootPath and WebRootPath?
We're ending up with the following ContentRoot and WebRoot when we run our app from IIS. 当我们从IIS运行我们的应用程序时,我们最终会得到以下ContentRoot和WebRoot。
ContentRoot: C:\MyApp\wwwroot
WebRoot: C:\MyApp\wwwroot\wwwroot
Here is how we are setting ContentRoot
and WebRoot
. 以下是我们设置
ContentRoot
和WebRoot
。
public class Startup
{
private readonly IHostingEnvironment _hostingEnv;
public Startup(IHostingEnvironment hostingEnv)
{
_hostingEnv = hostingEnv;
}
public void Configure(IApplicationBuilder app)
{
app.Run(context =>
{
// test output
context.Response.WriteAsync(_hostingEnv.ContentRootPath + "\r\n");
return context.Response.WriteAsync(_hostingEnv.WebRootPath + "\r\n");
});
}
public static void Main(string[] args)
{
var contentRoot = Directory.GetCurrentDirectory();
var webRoot = Path.Combine(contentRoot, "wwwroot");
var host = new WebHostBuilder()
.UseKestrel()
.UseIISPlatformHandlerUrl()
.UseContentRoot(contentRoot) // set content root
.UseWebRoot(webRoot) // set web root
.UseStartup<Startup>()
.Build();
host.Run();
}
}
From intellisense I see that... 从intellisense我看到......
How do we make the test output look instead like this: 我们如何使测试输出看起来像这样:
ContentRoot: C:\MyApp\
WebRoot: C:\MyApp\wwwroot\
While RC2 documentation is still being prepared, here is what I learned while trying to deploy pre-RC2 app as Azure Web App: 虽然RC2文档仍在准备中,但我在尝试将pre-RC2应用程序部署为Azure Web App时学到了以下内容:
There is no Visual Studio tooling yet, so the app must be published and deployed manually over FTP. 目前还没有Visual Studio工具,因此必须通过FTP手动发布和部署应用程序。 For publishing, use:
dotnet publish --configuration Release --output ./approot
对于发布,请使用:
dotnet publish --configuration Release --output ./approot
If connected to Azure over FTP, you will probably see something similar to: 如果通过FTP连接到Azure,您可能会看到类似于:
The "approot" folder can be replaced with the published one (the web.config is left in the approot). “approot”文件夹可以替换为已发布的文件夹(web.config保留在approot中)。
The "approot" must be configured as a virtual application in Azure Portal (the default was site\\wwwroot): 必须将“approot”配置为Azure门户中的虚拟应用程序(默认为site \\ wwwroot):
var currentDirectory = Directory.GetCurrentDirectory(); var host = new WebHostBuilder() .UseKestrel() .UseWebRoot(Path.Combine(currentDirectory, "..", "wwwroot")) .UseDefaultHostingConfiguration(args) .UseIISIntegration() .UseStartup<Startup>() .Build();
After these steps you should have ASPNET Core pre-RC2 web app running on Azure. 完成这些步骤后,您应该在Azure上运行ASPNET Core pre-RC2 Web应用程序。
In RC2, if we put the web.config
beside wwwroot
and point IIS at the MyApp
directory like this... 在RC2中,如果我们将
web.config
放在wwwroot
旁边并将IIS指向MyApp
目录,就像这样......
MyApp
web.config
wwwroot
...the code from the original question outputs this... ...来自原始问题的代码输出...
ContentRoot: C:\MyApp\
WebRoot: C:\MyApp\wwwroot\
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.