简体   繁体   English

我们如何设置ContentRootPath和WebRootPath?

[英]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 . 以下是我们设置ContentRootWebRoot

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我看到......

  • ContentRootPath contains the application content files. ContentRootPath包含应用程序内容文件。
  • WebRootPath contains the web-servable content files. WebRootPath包含可通过Web处理的内容文件。

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时学到了以下内容:

  1. 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

  2. If connected to Azure over FTP, you will probably see something similar to: 如果通过FTP连接到Azure,您可能会看到类似于:

在此输入图像描述

  1. The "approot" folder can be replaced with the published one (the web.config is left in the approot). “approot”文件夹可以替换为已发布的文件夹(web.config保留在approot中)。

  2. The "approot" must be configured as a virtual application in Azure Portal (the default was site\\wwwroot): 必须将“approot”配置为Azure门户中的虚拟应用程序(默认为site \\ wwwroot):

在此输入图像描述

  1. An the last thing to get static files served from the wwwroot folder, the Startup.cs file should be modified to include custom UseWebRoot call: 从wwwroot文件夹获取静态文件的最后一件事,应该修改Startup.cs文件以包含自定义UseWebRoot调用:
 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM