11

We're ending up with the following ContentRoot and WebRoot when we run our app from IIS.

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

Here is how we are setting ContentRoot and 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 the application content files.
  • WebRootPath contains the web-servable content files.

How do we make the test output look instead like this:

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

2 Answers 2

5

While RC2 documentation is still being prepared, here is what I learned while trying to deploy pre-RC2 app as Azure Web App:

  1. There is no Visual Studio tooling yet, so the app must be published and deployed manually over FTP. For publishing, use: dotnet publish --configuration Release --output ./approot

  2. If connected to Azure over FTP, you will probably see something similar to:

enter image description here

  1. The "approot" folder can be replaced with the published one (the web.config is left in the approot).

  2. The "approot" must be configured as a virtual application in Azure Portal (the default was site\wwwroot):

enter image description here

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

1
  • Update: for RC2, if the app is being deployed using kudu ("Deployment Source is configured in Azure Portal"), an additional environment variable must be set in Application properties in Azure Portal: SCM_TARGET_PATH with value "..\approot" (without quotes). Otherwise, the app will be deployed to \site\webroot and you will have \site\webroot\webroot
    – Zygimantas
    Commented May 20, 2016 at 8:58
2

In RC2, if we put the web.config beside wwwroot and point IIS at the MyApp directory like this...

MyApp
  web.config
  wwwroot

...the code from the original question outputs this...

ContentRoot:  C:\MyApp\
WebRoot:      C:\MyApp\wwwroot\
1
  • 1
    are you sure web.config should be beside wwwroot and not in wwwroot or inside approot as published? I am still searching for the correct location, because static files are not served once deployed in Azure web app, or .exe is not being executed.
    – Zygimantas
    Commented Apr 22, 2016 at 16:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.