3

I have two ASP.NET Core MVC projects. Both projects have the same files in their wwwroot folders.

My question: is it possible to specify a custom location for the wwwroot folder, so that I could access the same wwwroot folder in both projects?

I have already read similar questions like:

With the help of the above listed questions, I identified two approaches

  • using a virtual directory
  • including the files using app.UseFileServer

However, I was not able to reference the files using relative paths, e.g. in _Layout.html the reference ~/lib/bootstrap/dist/css/bootstrap.min.css does not work.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
CtrlC
  • 41
  • 4

2 Answers2

1

You can specify a custom WebRoot path in Program.cs:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
      .ConfigureWebHostDefaults(webBuilder =>
      {
         webBuilder.UseWebRoot("C:\path\to\folder");
         webBuilder.UseStartup<Startup>();
      });
Glynn Hurrell
  • 602
  • 6
  • 10
1

Not a direct answer for your question, but it helped me when I was looking for similar functionality, so leave it here for future seekers. If you are using ASP.NET Core 3.1, you can use a RazorClassLibrary, which allows you to share your static files between different projects. There is a great explanation in below article https://www.mikesdotnetting.com/article/330/including-static-resources-in-razor-class-libraries-in-asp-net-core