How to install ContentRootPath and WebRootPath?

We run the following ContentRoot and WebRoot when starting our application from IIS.

ContentRoot:  C:\MyApp\wwwroot
WebRoot:      C:\MyApp\wwwroot\wwwroot

This is how we install ContentRootand 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 ...

  • ContentRootPath contains application content files.
  • WebRootPath contains content files for web content.

How to make test output look like this:

ContentRoot:  C:\MyApp\
WebRoot:      C:\MyApp\wwwroot\
+4
source share
2 answers

In RC2, if we put web.confignext to wwwrootand specify IIS in a directory MyApplike this ...

MyApp
  web.config
  wwwroot

... the code from the original question deduces this ...

ContentRoot:  C:\MyApp\
WebRoot:      C:\MyApp\wwwroot\
0
source

RC2 , , pre-RC2 Azure Web App:

  • Visual Studio , FTP. : dotnet publish --configuration Release --output ./approot

  • Azure FTP , , :

enter image description here

  1. "approot" (web.config ).

  2. "" Azure Portal ( \wwwroot):

enter image description here

  1. , , wwwroot, Startup.cs UseWebRoot:
var currentDirectory = Directory.GetCurrentDirectory();

var host = new WebHostBuilder()
    .UseKestrel()
    .UseWebRoot(Path.Combine(currentDirectory, "..", "wwwroot"))
    .UseDefaultHostingConfiguration(args)
    .UseIISIntegration()
    .UseStartup<Startup>()
    .Build();

- ASPNET Core pre-RC2, Azure.

+2

All Articles