How to Configure an Alternative Folder to wwwroot in ASP.NET Core?

Is it possible to configure a different folder to replace wwwroot in ASP.NET Core?

Yes. Add a UseWebRoot call in your Program class:

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseWebRoot("myroot") // name it whatever you want
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();

    host.Run();
}

are there any side effects to this change?

Here are three that I can think of:

  1. The Bower package manager will not work properly, as it looks for a lib folder in wwwroot. I'm not certain if this is configurable.
  2. You will need to fix bundleconfig.json to look at the new directory.
  3. You will need to update the include portion in project.json to include your new directory in the publish output.

With Asp.Net Core 2.2 I did this: In the Configure method in Setup.cs I changed

app.UseStaticFiles();

to

app.UseStaticFiles(new StaticFileOptions
{
  FileProvider = new PhysicalFileProvider(Path.Combine(
    AppDomain.CurrentDomain.BaseDirectory,
    "myStaticFolder")),
});

Reference / Source and in English here

Tags:

Asp.Net Core