0

So I've been studying the documentation of.net Core Middleware and I'm working on a minimal Web API with an additional wwwroot folder containing static HTML content with CSS and Javascript. This is basically a demo for the Web API in the same project. The JS in this folder calls some of the API methods in it to provide various content.
But I want to use this API with several different domain names so they all share the same API. But the domains would each need their own wwwroot with static pages. And my Web API will use app.UseWhen() combined with the domain name to have some domain-specific methods per domain. This would allow me to have one site supporting multiple domains. This filtering based on domain names should be simple, but they would all share the same wwwroot. I want each domain to have it's own root.
Now, UseWebRoot() seems to solve this, except it gets called from the builder, not the app. This means I only get one where I want many.
It seems that app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "DomainName")) }) would work. (ContentRootPath, not WebRootPath, as I want the wwwroot folder to stay clean.)
Is this the proper approach to have custom static pages per domain?

These static files in the wwwroot will not be under control of the project itself, but are generated by another team member separately. They are front-end developers who just make things look more fancy per domain. (And in different languages where need be.) And while these sites could be different sites, I want to know if it can be contained inside one project.

Wim ten Brink
  • 25,901
  • 20
  • 83
  • 149
  • 1
    According to your post it works so why can't? I have an idea for your requirement it's only about css file why not use domain in front-end to get different files? Maybe in the front-end it could be included css by ```style-{domain}``` – MichaelMao Dec 29 '22 at 07:15
  • 1
    Does it work? I think it only make ```DomainName``` folder to static – MichaelMao Dec 29 '22 at 07:36
  • @MichaelMao More or less, yet. Sometimes it works but it's difficult to debug as it is domain name dependent. On a test server, it seemed to work but the it refused to load. And after an hour of testing and checking I discovered the site is unhappy about the SSL certificates that are used. Really annoying... – Wim ten Brink Dec 29 '22 at 15:18

0 Answers0