Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net-core

Is it possible to configure a different folder to replace wwwroot in ASP.NET Core? And, if yes, how? And are there any side effects to this change?

The only config that currently includes wwwroot in the entire project is found in project.json as seen in the code below; but replacing the value with the name of the new folder is not enough for the static file (ex: index.html) to be read.

"publishOptions": {
    "include": [
        "wwwroot",
        "web.config"
    ]
},
like image 985
usefulBee Avatar asked Nov 10 '16 19:11

usefulBee


1 Answers

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.
like image 70
Will Ray Avatar answered Sep 28 '22 03:09

Will Ray